|
| 1 | +name: Build precompiled NIFs |
| 2 | + |
| 3 | +env: |
| 4 | + NIF_DIRECTORY: "native/componentsguide_rustler_math" |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + tags: |
| 11 | + - '*' |
| 12 | + |
| 13 | +defaults: |
| 14 | + run: |
| 15 | + # Sets the working dir for "run" scripts. |
| 16 | + # Note that this won't change the directory for actions (tasks with "uses"). |
| 17 | + working-directory: "./native/componentsguide_rustler_math" |
| 18 | + |
| 19 | +jobs: |
| 20 | + build_release: |
| 21 | + name: NIF ${{ matrix.job.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) |
| 22 | + runs-on: ${{ matrix.job.os }} |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + job: |
| 27 | + # NIF version 2.16 |
| 28 | + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.16", use-cross: true } |
| 29 | + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.16", use-cross: true } |
| 30 | + - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.16" } |
| 31 | + - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.16" } |
| 32 | + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.16" } |
| 33 | + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.16", use-cross: true } |
| 34 | + - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.16" } |
| 35 | + - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.16" } |
| 36 | + # NIF version 2.15 |
| 37 | + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.15", use-cross: true } |
| 38 | + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.15", use-cross: true } |
| 39 | + - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.15" } |
| 40 | + - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.15" } |
| 41 | + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.15" } |
| 42 | + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.15", use-cross: true } |
| 43 | + - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.15" } |
| 44 | + - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.15" } |
| 45 | + # # NIF version 2.14 |
| 46 | + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , nif: "2.14", use-cross: true } |
| 47 | + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.14", use-cross: true } |
| 48 | + - { target: aarch64-apple-darwin , os: macos-11 , nif: "2.14" } |
| 49 | + - { target: x86_64-apple-darwin , os: macos-11 , nif: "2.14" } |
| 50 | + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , nif: "2.14" } |
| 51 | + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , nif: "2.14", use-cross: true } |
| 52 | + - { target: x86_64-pc-windows-gnu , os: windows-2019 , nif: "2.14" } |
| 53 | + - { target: x86_64-pc-windows-msvc , os: windows-2019 , nif: "2.14" } |
| 54 | + |
| 55 | + env: |
| 56 | + RUSTLER_NIF_VERSION: ${{ matrix.job.nif }} |
| 57 | + steps: |
| 58 | + - name: Checkout source code |
| 59 | + uses: actions/checkout@v2 |
| 60 | + |
| 61 | + - name: Install prerequisites |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + case ${{ matrix.job.target }} in |
| 65 | + arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; |
| 66 | + aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; |
| 67 | + esac |
| 68 | +
|
| 69 | + - name: Extract crate information |
| 70 | + shell: bash |
| 71 | + run: | |
| 72 | + echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV |
| 73 | + # Get the project version from mix.exs |
| 74 | + echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV |
| 75 | +
|
| 76 | + - name: Install Rust toolchain |
| 77 | + uses: actions-rs/toolchain@v1 |
| 78 | + with: |
| 79 | + toolchain: stable |
| 80 | + target: ${{ matrix.job.target }} |
| 81 | + override: true |
| 82 | + profile: minimal |
| 83 | + |
| 84 | + - name: Show version information (Rust, cargo, GCC) |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + gcc --version || true |
| 88 | + rustup -V |
| 89 | + rustup toolchain list |
| 90 | + rustup default |
| 91 | + cargo -V |
| 92 | + rustc -V |
| 93 | + rustc --print=cfg |
| 94 | +
|
| 95 | + - name: Download cross from GitHub releases |
| 96 | + uses: giantswarm/[email protected] |
| 97 | + if: ${{ matrix.job.use-cross }} |
| 98 | + with: |
| 99 | + binary: "cross" |
| 100 | + version: "v0.2.1" |
| 101 | + download_url: "https://github.com/rust-embedded/cross/releases/download/${version}/cross-${version}-x86_64-unknown-linux-gnu.tar.gz" |
| 102 | + tarball_binary_path: "${binary}" |
| 103 | + smoke_test: "${binary} --version" |
| 104 | + |
| 105 | + - name: Build |
| 106 | + shell: bash |
| 107 | + run: | |
| 108 | + if [ "${{ matrix.job.use-cross }}" == "true" ]; then |
| 109 | + cross build --release --target=${{ matrix.job.target }} |
| 110 | + else |
| 111 | + cargo build --release --target=${{ matrix.job.target }} |
| 112 | + fi |
| 113 | +
|
| 114 | + - name: Rename lib to the final name |
| 115 | + id: rename |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + LIB_PREFIX="lib" |
| 119 | + case ${{ matrix.job.target }} in |
| 120 | + *-pc-windows-*) LIB_PREFIX="" ;; |
| 121 | + esac; |
| 122 | +
|
| 123 | + # Figure out suffix of lib |
| 124 | + # See: https://doc.rust-lang.org/reference/linkage.html |
| 125 | + LIB_SUFFIX=".so" |
| 126 | + case ${{ matrix.job.target }} in |
| 127 | + *-apple-darwin) LIB_SUFFIX=".dylib" ;; |
| 128 | + *-pc-windows-*) LIB_SUFFIX=".dll" ;; |
| 129 | + esac; |
| 130 | +
|
| 131 | + CICD_INTERMEDIATES_DIR=$(mktemp -d) |
| 132 | +
|
| 133 | + # Setup paths |
| 134 | + LIB_DIR="${CICD_INTERMEDIATES_DIR}/released-lib" |
| 135 | + mkdir -p "${LIB_DIR}" |
| 136 | + LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}" |
| 137 | + LIB_PATH="${LIB_DIR}/${LIB_NAME}" |
| 138 | +
|
| 139 | + # Copy the release build lib to the result location |
| 140 | + cp "target/${{ matrix.job.target }}/release/${LIB_NAME}" "${LIB_DIR}" |
| 141 | +
|
| 142 | + # Final paths |
| 143 | + # In the end we use ".so" for MacOS in the final build |
| 144 | + # See: https://www.erlang.org/doc/man/erlang.html#load_nif-2 |
| 145 | + LIB_FINAL_SUFFIX="${LIB_SUFFIX}" |
| 146 | + case ${{ matrix.job.target }} in |
| 147 | + *-apple-darwin) LIB_FINAL_SUFFIX=".so" ;; |
| 148 | + esac; |
| 149 | +
|
| 150 | + LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.job.target }}${LIB_FINAL_SUFFIX}" |
| 151 | +
|
| 152 | + # Copy lib to final name on this directory |
| 153 | + cp "${LIB_PATH}" "${LIB_FINAL_NAME}" |
| 154 | +
|
| 155 | + tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}" |
| 156 | +
|
| 157 | + # Passes the path relative to the root of the project. |
| 158 | + LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz" |
| 159 | +
|
| 160 | + # Let subsequent steps know where to find the lib |
| 161 | + echo ::set-output name=LIB_FINAL_PATH::${LIB_FINAL_PATH} |
| 162 | + echo ::set-output name=LIB_FINAL_NAME::${LIB_FINAL_NAME}.tar.gz |
| 163 | +
|
| 164 | + - name: "Artifact upload" |
| 165 | + uses: actions/upload-artifact@v2 |
| 166 | + with: |
| 167 | + name: ${{ steps.rename.outputs.LIB_FINAL_NAME }} |
| 168 | + path: ${{ steps.rename.outputs.LIB_FINAL_PATH }} |
| 169 | + |
| 170 | + - name: Publish archives and packages |
| 171 | + uses: softprops/action-gh-release@v1 |
| 172 | + with: |
| 173 | + files: | |
| 174 | + ${{ steps.rename.outputs.LIB_FINAL_PATH }} |
| 175 | + if: startsWith(github.ref, 'refs/tags/') |
0 commit comments