Build for Selected Target #36
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build for Selected Target | |
on: | |
workflow_dispatch: | |
inputs: | |
target: | |
description: "Build Target" | |
required: true | |
type: choice | |
options: | |
- 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 | |
defaults: | |
run: | |
shell: bash | |
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' || 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=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.10" | |
- name: Set 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 "$PYTHON_PATH" >> $GITHUB_PATH | |
env: | |
PYTHON_PATH: ${{ env.PYTHON_PATH }} | |
- name: Setup Cross-Compilation Environment | |
run: | | |
# Set up environment variables for cross-compilation | |
case "${{ github.event.inputs.target }}" in | |
"aarch64-unknown-linux-gnu") | |
sudo apt-get update | |
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
;; | |
esac | |
echo "PYO3_CROSS=1" >> $GITHUB_ENV | |
echo "PYO3_CROSS_PYTHON_VERSION=3.10" >> $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 | |
# Debug: List contents of the Python installation directory | |
ls -l "$(dirname $PYTHON_PATH)" | |
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 | |
env: | |
PYTHON_PATH: ${{ env.PYTHON_PATH }} | |
- name: Print debugging information | |
run: | | |
python --version | |
which python | |
echo "PATH: $PATH" | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ steps.set-vars.outputs.target }} | |
- name: Extract version | |
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV | |
env: | |
GITHUB_REF: ${{ github.ref }} | |
- name: Release Tgs Binary | |
id: tgs | |
run: bash .github/workflows/release-pkg.sh | |
env: | |
BIN_NAME: ${{ steps.set-vars.outputs.bin_name }} | |
TARGET: ${{ steps.set-vars.outputs.target }} | |
OS: ${{ steps.set-vars.outputs.os }} | |
- name: Publish Archive | |
uses: softprops/[email protected] | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
draft: true | |
files: ${{ steps.tgs.outputs.archive }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
build-macos: | |
name: Build for MacOS | |
runs-on: macos-latest | |
if: ${{ github.event.inputs.target == 'x86_64-apple-darwin' || github.event.inputs.target == 'aarch64-apple-darwin' }} | |
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=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" | |
- name: Set environment variables | |
run: | | |
echo "PYO3_PYTHON=python" >> $GITHUB_ENV | |
- name: Add Python to PATH | |
run: echo "$pythonLocation/bin" >> $GITHUB_PATH | |
env: | |
pythonLocation: /opt/hostedtoolcache/Python/3.12.1/x64 | |
- name: Print debugging information | |
run: | | |
python --version | |
which python | |
echo "PATH: $PATH" | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ steps.set-vars.outputs.target }} | |
- name: Extract version | |
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV | |
env: | |
GITHUB_REF: ${{ github.ref }} | |
- name: Release Tgs Binary | |
id: tgs | |
run: bash .github/workflows/release-pkg.sh | |
env: | |
BIN_NAME: ${{ steps.set-vars.outputs.bin_name }} | |
TARGET: ${{ steps.set-vars.outputs.target }} | |
OS: ${{ steps.set-vars.outputs.os }} | |
- name: Publish Archive | |
uses: softprops/[email protected] | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
draft: true | |
files: ${{ steps.tgs.outputs.archive }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |