Skip to content

Commit

Permalink
ci: build nifs using cross
Browse files Browse the repository at this point in the history
  • Loading branch information
metaclips committed Mar 6, 2024
1 parent d10556b commit d527dac
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 43 deletions.
62 changes: 37 additions & 25 deletions .github/workflows/release-draft-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,47 +352,59 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [arm64, amd64]
include:
- build: arm64
os: ubuntu-22.04
target: aarch64-unknown-linux-gnu
- build: amd64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
runs-on: ${{ matrix.os }}
job:
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 }
- { target: aarch64-apple-darwin , os: macos-14 }
- { target: x86_64-apple-darwin , os: macos-14 }

runs-on: ${{ matrix.job.os }}
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
ref: ${{ github.event.inputs.release_branch }}

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1 # https://github.com/docker/setup-qemu-action
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.job.target }}

- name: Install Cross
if: matrix.job.use-cross == true
run: cargo install --version 0.2.4 cross

- name: Build NIF For Linux
shell: bash
- name: Build NIFs
run: |
set -ex
docker build --platform linux/${{ matrix.build }} --tag ghcr.io/build-trust/nif:latest --file tools/docker/nifs/Dockerfile .
id=$(docker create ghcr.io/build-trust/nif:latest)
docker cp "${id}:/work/implementations/elixir/ockam/ockly/priv/native/libockam_rust_elixir_nifs.so" .
if [[ '${{ matrix.job.use-cross }}' == 'true' ]]; then
cross build --target ${{ matrix.job.target }} -p ockam_rust_elixir_nifs --release
exit
fi
rustup target add ${{ matrix.job.target }}
cargo build --target ${{ matrix.job.target }} -p ockam_rust_elixir_nifs --release
- name: List
run: |
ls target/${{ matrix.job.target }}/release/
- name: Rename NIF
- name: Rename Build
run: |
cargo install tomlq
ockam_version=$(eval "tomlq package.version -f implementations/rust/ockam/ockam/Cargo.toml")
# 2.15 indicates that we will be using OTP version 2.15 as it's the oldest version
cp libockam_rust_elixir_nifs.so libockam_rust_elixir_nifs-v${ockam_version}-nif-2.15-${{ matrix.target }}.so &&
tar -zcvf "libockam_rust_elixir_nifs-v${ockam_version}-nif-2.15-${{ matrix.target }}.so.tar.gz" libockam_rust_elixir_nifs-v${ockam_version}-nif-2.15-${{ matrix.target }}.so
final_name="libockam_rust_elixir_nifs-v${ockam_version}-nif-2.15-${{ matrix.job.target }}.so"
if [[ "${{ matrix.job.target }}" == *"darwin"* ]]; then
cp target/${{ matrix.job.target }}/release/libockam_rust_elixir_nifs.dylib "$final_name"
else
cp target/${{ matrix.job.target }}/release/libockam_rust_elixir_nifs.so "$final_name"
fi
echo "FILE_NAME=libockam_rust_elixir_nifs-v${ockam_version}-nif-2.15-${{ matrix.target }}.so.tar.gz" >> $GITHUB_ENV
tar -zcvf "${final_name}.tar.gz" "$final_name"
echo "FILE_NAME=${final_name}.tar.gz" >> $GITHUB_ENV
- name: Install Cosign
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ inherits = "test"
opt-level = 2
[profile.dev.package.adler]
opt-level = 1

# Allows us build with cross across multiple platforms.
[workspace.metadata.cross.build]
# additional commands to run prior to building the package
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH",
]
9 changes: 8 additions & 1 deletion implementations/elixir/ockam/ockly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ by adding `ockly` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ockly, "~> 0.1.0"}
{:ockly, "~> 0.117.0"}
]
end
```
Expand All @@ -19,3 +19,10 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/ockly>.

## Using NIF

NIFs are built during every Ockam release and used in production, e.g. during [healthcheck docker build](https://github.com/build-trust/ockam/blob/develop/tools/docker/healthcheck/Dockerfile), to use a precompiled NIF, we need to set `OCKAM_DOWNLOAD_NIF` to `true or 1` which will download the NIF from our GitHub release.

## Updating Precompile NIF Version

When using a precompiled NIF, we compare the SHA of the precompiled NIF downloaded from GitHub release with that stored in the `checksum-Elixir.Ockly.Native.exs` file. To update the default precompiled NIF version to use in the Ockly library, we need to update the SHASum of supported NIF architechtures in the `checksum-Elixir.Ockly.Native.exs` file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%{
"libockam_rust_elixir_nifs-v0.117.0-nif-2.15-aarch64-apple-darwin.so.tar.gz" =>
"sha256:56a94c3c302343b374e8870ea957c478ab2a173484bb4e9391e4dc1189ab8563",
"libockam_rust_elixir_nifs-v0.117.0-nif-2.15-aarch64-unknown-linux-gnu.so.tar.gz" =>
"sha256:d3727b83a1530533e2d0348637a11dec8035bec77a0cd42d926ed20ff20bfbd2",
"libockam_rust_elixir_nifs-v0.117.0-nif-2.15-x86_64-apple-darwin.so.tar.gz" =>
"sha256:74098968a3701733397eec22d95dded2cf1eca137e56b6560fc49ee4ed64ec2b",
"libockam_rust_elixir_nifs-v0.117.0-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz" =>
"sha256:8c71aaf8e1924cb48842bc905d9ecc75f9941ddccd52e0b1b884d22b4a2cb810"
}
17 changes: 0 additions & 17 deletions tools/docker/nifs/Dockerfile

This file was deleted.

0 comments on commit d527dac

Please sign in to comment.