diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..b968b9a --- /dev/null +++ b/.cargo/config.toml @@ -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" diff --git a/.github/workflows/cross-compiling-env.sh b/.github/workflows/cross-compiling-env.sh new file mode 100644 index 0000000..072a562 --- /dev/null +++ b/.github/workflows/cross-compiling-env.sh @@ -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 diff --git a/.github/workflows/dispatch-test.yml b/.github/workflows/dispatch-test.yml index 80e44cf..71a5fc2 100644 --- a/.github/workflows/dispatch-test.yml +++ b/.github/workflows/dispatch-test.yml @@ -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: | @@ -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 }}" diff --git a/.github/workflows/release-pkg.sh b/.github/workflows/release-pkg.sh index 01fb2b3..7d17ad2 100755 --- a/.github/workflows/release-pkg.sh +++ b/.github/workflows/release-pkg.sh @@ -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" @@ -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="" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7922dac..9a7ab10 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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}} @@ -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: | diff --git a/.gitignore b/.gitignore index b57ad5e..93457c8 100644 --- a/.gitignore +++ b/.gitignore @@ -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