From d10556b07478738fee13844e9c62635b6c95a8a8 Mon Sep 17 00:00:00 2001 From: Michael Uti Date: Mon, 4 Mar 2024 17:47:29 +0100 Subject: [PATCH] chore: only build nifs if `OCKAM_DOWNLOAD_NIF` is not set --- .github/workflows/elixir.yml | 3 --- .github/workflows/make.yml | 3 --- .../elixir/ockam/ockly/lib/ockly/native.ex | 2 +- .../ockam_rust_elixir_nifs/.cargo/config.toml | 15 --------------- .../rust/ockam/ockam_rust_elixir_nifs/README.md | 2 +- .../rust/ockam/ockam_rust_elixir_nifs/build.rs | 3 +++ tools/docker/healthcheck/Dockerfile | 1 + tools/docker/nifs/Dockerfile | 2 +- 8 files changed, 7 insertions(+), 24 deletions(-) diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 5275d70c18e..047fba6e2a4 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -55,9 +55,6 @@ defaults: run: shell: nix develop ../../tools/nix#elixir --command bash {0} -env: - OCKAM_BUILD_NIF: true - jobs: test: name: Elixir - test diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 059666eea60..02f9b15ab3e 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -38,9 +38,6 @@ defaults: run: shell: nix develop ./tools/nix --command bash {0} -env: - OCKAM_BUILD_NIF: true - jobs: full_build_in_release_mode: name: Make - full_build_in_release_mode diff --git a/implementations/elixir/ockam/ockly/lib/ockly/native.ex b/implementations/elixir/ockam/ockly/lib/ockly/native.ex index 90229ee3c55..2e2f739e0cb 100644 --- a/implementations/elixir/ockam/ockly/lib/ockly/native.ex +++ b/implementations/elixir/ockam/ockly/lib/ockly/native.ex @@ -7,7 +7,7 @@ defmodule Ockly.Native do otp_app: :ockly, crate: "ockam_rust_elixir_nifs", path: "../../../rust/ockam/ockam_rust_elixir_nifs", - force_build: System.get_env("OCKAM_BUILD_NIF") in ["1", "true"], + force_build: System.get_env("OCKAM_DOWNLOAD_NIF") == nil, version: version, load_from: {:ockly, "priv/native/libockam_rust_elixir_nifs"}, # This is a fake link, I'll update after deploying a released nif diff --git a/implementations/rust/ockam/ockam_rust_elixir_nifs/.cargo/config.toml b/implementations/rust/ockam/ockam_rust_elixir_nifs/.cargo/config.toml index d5f7b11aad1..e69de29bb2d 100644 --- a/implementations/rust/ockam/ockam_rust_elixir_nifs/.cargo/config.toml +++ b/implementations/rust/ockam/ockam_rust_elixir_nifs/.cargo/config.toml @@ -1,15 +0,0 @@ -[target.'cfg(target_os = "macos")'] -rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", -] - -# See https://github.com/rust-lang/rust/issues/59302 -[target.x86_64-unknown-linux-musl] -rustflags = [ - "-C", "target-feature=-crt-static" -] - -# Provides a small build size, but takes more time to build. -[profile.release] -lto = true diff --git a/implementations/rust/ockam/ockam_rust_elixir_nifs/README.md b/implementations/rust/ockam/ockam_rust_elixir_nifs/README.md index 6f01faddf48..ddbaab7ecca 100644 --- a/implementations/rust/ockam/ockam_rust_elixir_nifs/README.md +++ b/implementations/rust/ockam/ockam_rust_elixir_nifs/README.md @@ -34,7 +34,7 @@ Add this to your `Cargo.toml`: ``` [dependencies] -ockam_rust_elixir_nifs = "0.1.0" +ockam_rust_elixir_nifs = "0.117.0" ``` ## License diff --git a/implementations/rust/ockam/ockam_rust_elixir_nifs/build.rs b/implementations/rust/ockam/ockam_rust_elixir_nifs/build.rs index 3e0c3d8ea77..77337ef662b 100644 --- a/implementations/rust/ockam/ockam_rust_elixir_nifs/build.rs +++ b/implementations/rust/ockam/ockam_rust_elixir_nifs/build.rs @@ -1,5 +1,8 @@ use std::env::consts; +// When running cargo build from the workspace end, we can't directly +// pass these rustflag only for the nif crate, so I'll be adding the flags +// to this file. fn main() { if consts::OS == "macos" { println!("cargo:rustc-link-arg=-undefined"); diff --git a/tools/docker/healthcheck/Dockerfile b/tools/docker/healthcheck/Dockerfile index d61e4439488..be530a39942 100644 --- a/tools/docker/healthcheck/Dockerfile +++ b/tools/docker/healthcheck/Dockerfile @@ -5,6 +5,7 @@ COPY --from=cgr.dev/chainguard/wolfi-base /bin /bin COPY --from=cgr.dev/chainguard/wolfi-base /usr/bin /usr/bin ENV PATH=/root/.cargo/bin:$PATH +ENV OCKAM_DOWNLOAD_NIF="1" COPY . /work RUN set -ex; \ cd work; \ diff --git a/tools/docker/nifs/Dockerfile b/tools/docker/nifs/Dockerfile index 1bb9f712289..61949687206 100644 --- a/tools/docker/nifs/Dockerfile +++ b/tools/docker/nifs/Dockerfile @@ -12,6 +12,6 @@ RUN set -ex; \ rustup-init --no-update-default-toolchain -y; \ rustup show; \ cargo --version; \ - OCKAM_BUILD_NIF=true make elixir_build_ockly; + make elixir_build_ockly; CMD ["sh"]