|
| 1 | +name: build |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [ master ] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-linux: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + container: |
| 18 | + image: quay.io/pypa/manylinux_2_28_x86_64 |
| 19 | + |
| 20 | + env: |
| 21 | + CARGO_TERM_COLOR: always |
| 22 | + PYTHON_BIN: /opt/python/cp311-cp311/bin/python |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + submodules: true |
| 29 | + |
| 30 | + - name: Install Rust (via rustup) |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable |
| 34 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 35 | +
|
| 36 | + - name: Install build dependencies |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + yum install -y jq llvm clang |
| 40 | +
|
| 41 | + - name: Install Python build dependencies |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + $PYTHON_BIN -m pip install --upgrade pip |
| 45 | + $PYTHON_BIN -m pip install wheel auditwheel |
| 46 | +
|
| 47 | + - name: Generate lock file |
| 48 | + shell: bash |
| 49 | + run: cargo generate-lockfile |
| 50 | + |
| 51 | + - name: Compute package version |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version') |
| 55 | + echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV" |
| 56 | +
|
| 57 | + - name: Build Rust binary (release, stub linkage) |
| 58 | + shell: bash |
| 59 | + env: |
| 60 | + IDALIB_FORCE_STUB_LINKAGE: "1" |
| 61 | + run: cargo build --release |
| 62 | + |
| 63 | + - name: Build Python wheel skeleton |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + mkdir -p target/wheels |
| 67 | + $PYTHON_BIN -m pip wheel --no-deps ./dist/pypi -w ./target/wheels |
| 68 | +
|
| 69 | + - name: Merge Rust binary into wheel |
| 70 | + shell: bash |
| 71 | + run: | |
| 72 | + cd target/wheels |
| 73 | +
|
| 74 | + # unpack the wheel built by the ./dist/pypi package |
| 75 | + $PYTHON_BIN -m wheel unpack parascope-${PACKAGE_VERSION}*.whl |
| 76 | +
|
| 77 | + # copy the compiled Rust binary into .data/scripts as rparascope |
| 78 | + mkdir -p parascope-${PACKAGE_VERSION}/parascope-${PACKAGE_VERSION}.data/scripts |
| 79 | + cp ../release/parascope parascope-${PACKAGE_VERSION}/parascope-${PACKAGE_VERSION}.data/scripts/rparascope |
| 80 | +
|
| 81 | + # repack |
| 82 | + $PYTHON_BIN -m wheel pack parascope-${PACKAGE_VERSION} -d . |
| 83 | +
|
| 84 | + - name: Repair wheel with auditwheel (manylinux tagging & bundling) |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + cd target/wheels |
| 88 | + WHEEL=$(ls parascope-${PACKAGE_VERSION}-*.whl) |
| 89 | + echo "Repairing $WHEEL with auditwheel" |
| 90 | + $PYTHON_BIN -m auditwheel repair parascope-${PACKAGE_VERSION}-*.whl -w . |
| 91 | + echo "Removing original wheel" |
| 92 | + rm "$WHEEL" |
| 93 | +
|
| 94 | + - name: Upload Linux wheel |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: wheels-linux |
| 98 | + path: target/wheels/*.whl |
| 99 | + |
| 100 | + build-macos: |
| 101 | + runs-on: macOS-latest |
| 102 | + steps: |
| 103 | + - name: checkout |
| 104 | + uses: actions/checkout@v4 |
| 105 | + with: |
| 106 | + submodules: true |
| 107 | + |
| 108 | + - name: Install Rust (via rustup) |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain stable |
| 112 | + echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 113 | +
|
| 114 | + - name: Setup Python |
| 115 | + uses: actions/setup-python@v5 |
| 116 | + with: |
| 117 | + python-version: "3.11" |
| 118 | + |
| 119 | + - name: Install Python build dependencies |
| 120 | + run: | |
| 121 | + python -m pip install --upgrade pip |
| 122 | + python -m pip install wheel |
| 123 | +
|
| 124 | + - name: Generate lock file |
| 125 | + shell: bash |
| 126 | + run: cargo generate-lockfile |
| 127 | + |
| 128 | + - name: Compute package version |
| 129 | + shell: bash |
| 130 | + run: | |
| 131 | + VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version') |
| 132 | + echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV" |
| 133 | +
|
| 134 | + - name: Build Rust binary (release, stub linkage) |
| 135 | + env: |
| 136 | + IDALIB_FORCE_STUB_LINKAGE: "1" |
| 137 | + run: cargo build --release |
| 138 | + |
| 139 | + - name: Detect macOS arch from binary |
| 140 | + shell: bash |
| 141 | + run: | |
| 142 | + ARCH=$(lipo -info target/release/parascope | grep -oE 'x86_64|arm64') |
| 143 | + if [ "$ARCH" = "x86_64" ]; then |
| 144 | + PLATFORM_TAG="macosx_10_9_x86_64" |
| 145 | + elif [ "$ARCH" = "arm64" ]; then |
| 146 | + PLATFORM_TAG="macosx_11_0_arm64" |
| 147 | + else |
| 148 | + echo "Unknown arch from lipo: $ARCH" |
| 149 | + exit 1 |
| 150 | + fi |
| 151 | + echo "PLATFORM_TAG=$PLATFORM_TAG" >> "$GITHUB_ENV" |
| 152 | +
|
| 153 | + - name: Build Python wheel skeleton |
| 154 | + run: | |
| 155 | + mkdir -p target/wheels |
| 156 | + python -m pip wheel --no-deps ./dist/pypi -w ./target/wheels |
| 157 | +
|
| 158 | + - name: Merge Rust binary into wheel |
| 159 | + run: | |
| 160 | + cd target/wheels |
| 161 | + python -m wheel unpack parascope-${PACKAGE_VERSION}*.whl |
| 162 | +
|
| 163 | + mkdir -p parascope-${PACKAGE_VERSION}/parascope-${PACKAGE_VERSION}.data/scripts |
| 164 | + cp ../release/parascope parascope-${PACKAGE_VERSION}/parascope-${PACKAGE_VERSION}.data/scripts/rparascope |
| 165 | +
|
| 166 | + python -m wheel pack parascope-${PACKAGE_VERSION} -d . |
| 167 | +
|
| 168 | + - name: Retag macOS wheel with platform tag |
| 169 | + shell: bash |
| 170 | + run: | |
| 171 | + cd target/wheels |
| 172 | + WHEEL=$(ls parascope-${PACKAGE_VERSION}-*.whl) |
| 173 | + echo "Retagging $WHEEL to platform $PLATFORM_TAG" |
| 174 | + python -m wheel tags --platform-tag "$PLATFORM_TAG" "$WHEEL" |
| 175 | + echo "Removing original wheel" |
| 176 | + rm "$WHEEL" |
| 177 | +
|
| 178 | + - name: Upload macOS wheel |
| 179 | + uses: actions/upload-artifact@v4 |
| 180 | + with: |
| 181 | + name: wheels-macos |
| 182 | + path: target/wheels/*.whl |
0 commit comments