Skip to content

Commit

Permalink
Merge pull request #62 from warpy-ai/adjust_enviroments
Browse files Browse the repository at this point in the history
Adjust enviroments
  • Loading branch information
jucasoliveira authored Jan 30, 2024
2 parents 301c552 + b213832 commit e170ab6
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 78 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.x86_64-unknown-linux-gnu]
linker = "x86_64-linux-gnu-gcc"

[target.riscv64gc-unknown-linux-gnu]
linker = "riscv64gc-unknown-linux-gnu-gcc"
95 changes: 95 additions & 0 deletions .github/workflows/cross-compiling-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Ensure script fails on error
set -euo pipefail
set -o errexit
set -o nounset
set -o xtrace


TARGET=${TARGET}
PYTHON_PATH=${PYTHON_PATH}

# Set up environment variables for cross-compilation
case "${TARGET}" in
"aarch64-unknown-linux-gnu")
sudo apt-get update
sudo apt-get install libxcb-composite0-dev -y
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
wget https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.10.13+20240107-aarch64-unknown-linux-gnu-install_only.tar.gz
tar -xzvf cpython-3.10.13+20240107-aarch64-unknown-linux-gnu-install_only.tar.gz

PYTHON_LIB_DIR=$(pwd)/python/lib
export LD_LIBRARY_PATH=$PYTHON_LIB_DIR:${LD_LIBRARY_PATH:-}

# Set PKG_CONFIG_PATH, handling the case where it might not be set
if [ -z "${PKG_CONFIG_PATH+x}" ]; then
# PKG_CONFIG_PATH is not set
export PKG_CONFIG_PATH=$PYTHON_LIB_DIR/pkgconfig
else
# PKG_CONFIG_PATH is set, append to it
export PKG_CONFIG_PATH=$PYTHON_LIB_DIR/pkgconfig:$PKG_CONFIG_PATH
fi

export RUSTFLAGS="-C link-args=-Wl,-rpath,/home/runner/work/tgs/tgs/python/lib -C link-arg=-L/home/runner/work/tgs/tgs/python/lib"


echo "Listing contents of Python installation directory for aarch64..."
ls -l "$PYTHON_LIB_DIR"
;;
"x86_64-unknown-linux-gnu")
sudo apt-get update
sudo apt-get install libxcb-composite0-dev -y
sudo apt-get install -y gcc-x86-64-linux-gnu g++-x86-64-linux-gnu
# Dynamically set the Python library directory
# Assuming the lib directory is at the same level as bin
PYTHON_LIB_DIR="$(dirname ${PYTHON_PATH})/lib"
echo "PYO3_CROSS_LIB_DIR=$PYTHON_LIB_DIR" >> $GITHUB_ENV
ls -l "$(dirname $(which python))"
;;
"x86_64-unknown-linux-musl")
sudo apt-get update
sudo apt-get install libxcb-composite0-dev -y
sudo apt-get install -y musl-tools musl-dev
# Create a custom wrapper script for musl-g++
echo '#!/bin/bash' | sudo tee /usr/local/bin/custom-musl-g++

# Set environment variables for custom wrapper
echo 'CXX=g++' >> $GITHUB_ENV
echo 'CXXFLAGS=-I/usr/include/x86_64-linux-musl' >> $GITHUB_ENV
echo 'LDFLAGS=-L/usr/lib/x86_64-linux-musl' >> $GITHUB_ENV
# Dynamically set the Python library directory
# Assuming the lib directory is at the same level as bin
PYTHON_LIB_DIR="$(dirname ${PYTHON_PATH})/lib"
echo "PYO3_CROSS_LIB_DIR=$PYTHON_LIB_DIR" >> $GITHUB_ENV
;;
"aarch64-apple-darwin")
# macOS specific setup (if necessary)
# Dynamically set the Python library directory
# Assuming the lib directory is at the same level as bin
PYTHON_LIB_DIR="$(dirname ${PYTHON_PATH})/lib"
echo "PYO3_CROSS_LIB_DIR=$PYTHON_LIB_DIR" >> $GITHUB_ENV
;;
"x86_64-apple-darwin")
# macOS specific setup (if necessary)
# Dynamically set the Python library directory
# Assuming the lib directory is at the same level as bin
PYTHON_LIB_DIR="$(dirname ${PYTHON_PATH})/lib"
echo "PYO3_CROSS_LIB_DIR=$PYTHON_LIB_DIR" >> $GITHUB_ENV
;;
esac

# Set PYO3 environment variables
echo "PYO3_CROSS=1" >> $GITHUB_ENV
echo "PYO3_CROSS_PYTHON_VERSION=3.10" >> $GITHUB_ENV

# Debug: List contents of the Python installation directory
echo "Listing contents of Python installation directory..."
ls -l "$(dirname $(which python))"
ls -l "$PYTHON_LIB_DIR"

# Verify if the directory exists
if [ ! -d "$PYTHON_LIB_DIR" ]; then
echo "Python library directory for cross-compilation does not exist: $PYTHON_LIB_DIR"
exit 1
fi
38 changes: 16 additions & 22 deletions .github/workflows/dispatch-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,38 @@ jobs:
build-linux:
name: Build for Linux
runs-on: ubuntu-latest
if: ${{ github.event.inputs.target == 'x86_64-unknown-linux-gnu' || github.event.inputs.target == 'aarch64-unknown-linux-gnu' }}
if: ${{ github.event.inputs.target == 'x86_64-unknown-linux-gnu' || github.event.inputs.target == 'aarch64-unknown-linux-gnu' || github.event.inputs.target == 'x86_64-unknown-linux-musl' || github.event.inputs.target == 'riscv64gc-unknown-linux-gnu' || github.event.inputs.target == 'armv7-unknown-linux-gnueabihf'}}
steps:
- uses: actions/checkout@v4

- name: Set variables
id: set-vars
run: |
case "${{ github.event.inputs.target }}" in
"x86_64-unknown-linux-gnu"|"x86_64-unknown-linux-musl"|"aarch64-unknown-linux-gnu"|"armv7-unknown-linux-gnueabihf"|"riscv64gc-unknown-linux-gnu")
echo "::set-output name=os::ubuntu-latest"
;;
"aarch64-apple-darwin"|"x86_64-apple-darwin")
echo "::set-output name=os::macos-latest"
;;
esac
echo "::set-output name=os::ubuntu-latest"
echo "::set-output name=bin_name::tgs"
echo "::set-output name=target::${{ github.event.inputs.target }}"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
python-version: "3.10"

- name: Set environment variables
- name: Set Python environment variables
run: |
echo "PYO3_PYTHON=python" >> $GITHUB_ENV
# Dynamically determine the Python installation path
PYTHON_PATH=$(dirname $(which python))
echo "PYTHON_PATH=${PYTHON_PATH}" >> $GITHUB_ENV
- name: Add Python to PATH
run: echo "$pythonLocation/bin" >> $GITHUB_PATH
run: echo "$PYTHON_PATH" >> $GITHUB_PATH
env:
pythonLocation: /opt/hostedtoolcache/Python/3.12.1/x64
PYTHON_PATH: ${{ env.PYTHON_PATH }}

- name: Setup Cross-Compilation Environment
run: bash .github/workflows/cross-compiling-env.sh
env:
PYTHON_PATH: ${{ env.PYTHON_PATH }}
TARGET: ${{ steps.set-vars.outputs.target }}

- name: Print debugging information
run: |
Expand Down Expand Up @@ -99,14 +100,7 @@ jobs:
- name: Set variables
id: set-vars
run: |
case "${{ github.event.inputs.target }}" in
"x86_64-unknown-linux-gnu"|"x86_64-unknown-linux-musl"|"aarch64-unknown-linux-gnu"|"armv7-unknown-linux-gnueabihf"|"riscv64gc-unknown-linux-gnu")
echo "::set-output name=os::ubuntu-latest"
;;
"aarch64-apple-darwin"|"x86_64-apple-darwin")
echo "::set-output name=os::macos-latest"
;;
esac
echo "::set-output name=os::macos-latest"
echo "::set-output name=bin_name::tgs"
echo "::set-output name=target::${{ github.event.inputs.target }}"
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# Ensure script fails on error
set -euo pipefail
set -o errexit
set -o nounset
set -o xtrace

# Variables from the GitHub Actions workflow
BIN_NAME=${BIN_NAME}
VERSION=$(git describe --tags --always)
TARGET=${TARGET}
OS=${OS:-"default_os"}
OS=${OS}
DIST_DIR="./output"

echo "Packaging $BIN_NAME v$VERSION for $TARGET on $OS"
Expand All @@ -18,7 +21,7 @@ rm -rf "$DIST_DIR/*"

# Build the project
echo "Building $BIN_NAME..."
cargo build --release --target "$TARGET"
cargo build --release --target "$TARGET" --verbose

# Copy binaries to distribution directory
ARCHIVE_NAME=""
Expand Down
68 changes: 15 additions & 53 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,69 +23,22 @@ jobs:
- aarch64-apple-darwin
- x86_64-apple-darwin
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
- riscv64gc-unknown-linux-gnu
include:
- target: aarch64-apple-darwin
os: macos-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
python-version: "3.10"
- target: x86_64-apple-darwin
os: macos-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: x86_64-pc-windows-msvc
extra: "bin"
os: windows-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: x86_64-pc-windows-msvc
extra: msi
os: windows-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: aarch64-pc-windows-msvc
extra: "bin"
os: windows-latest
target_rustflags: ""
python-version: "3.x"
- target: aarch64-pc-windows-msvc
extra: msi
os: windows-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
python-version: "3.10"
- target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: x86_64-unknown-linux-musl
os: ubuntu-20.04
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: aarch64-unknown-linux-gnu
os: ubuntu-20.04
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-20.04
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
- target: riscv64gc-unknown-linux-gnu
os: ubuntu-latest
target_rustflags: ""
bin_name: "tgs"
python-version: "3.x"
python-version: "3.10"

runs-on: ${{matrix.os}}

Expand All @@ -97,14 +50,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set environment variables
- name: Set Python environment variables
run: |
echo "PYO3_PYTHON=python" >> $GITHUB_ENV
# Dynamically determine the Python installation path
PYTHON_PATH=$(dirname $(which python))
echo "PYTHON_PATH=${PYTHON_PATH}" >> $GITHUB_ENV
- name: Add Python to PATH
run: echo "$pythonLocation/bin" >> $GITHUB_PATH
run: echo "$PYTHON_PATH" >> $GITHUB_PATH
env:
PYTHON_PATH: ${{ env.PYTHON_PATH }}

- name: Setup Cross-Compilation Environment
run: bash .github/workflows/cross-compiling-env.sh
env:
pythonLocation: /opt/hostedtoolcache/Python/3.12.1/x64
PYTHON_PATH: ${{ env.PYTHON_PATH }}
TARGET: ${{ matrix.target }}

- name: Print debugging information
run: |
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# More information here: https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

.cargo
# These are backup files generated by rustfmt
**/*.rs.bk

Expand Down

0 comments on commit e170ab6

Please sign in to comment.