diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index 07c4327..3c95007 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -5,6 +5,10 @@ name: Elixir CI +env: + MIX_ENV: test + RUSTLER_PRECOMPILATION_YEX_BUILD: "true" + on: push: branches: [ "main" ] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5618a62 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,94 @@ +name: Build precompiled NIFs + +on: + push: + branches: + - main + tags: + - '*' + +jobs: + build_release: + name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) + runs-on: ${{ matrix.job.os }} + strategy: + fail-fast: false + matrix: + nif: ["2.16", "2.15"] + job: + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true } + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true } + - { target: aarch64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true } + - { target: aarch64-apple-darwin , os: macos-12 } + - { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true } + - { target: x86_64-apple-darwin , os: macos-12 } + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 } + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true } + - { target: x86_64-pc-windows-gnu , os: windows-2019 } + - { target: x86_64-pc-windows-msvc , os: windows-2019 } + + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Extract project version + shell: bash + run: | + # Get the project version from mix.exs + echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: ${{ matrix.job.target }} + + - name: Build the project + id: build-crate + uses: philss/rustler-precompiled-action@v1.0.1 + with: + project-name: yex + project-version: ${{ env.PROJECT_VERSION }} + target: ${{ matrix.job.target }} + nif-version: ${{ matrix.nif }} + use-cross: ${{ matrix.job.use-cross }} + project-dir: "native/yex" + + - name: Artifact upload + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.build-crate.outputs.file-name }} + path: ${{ steps.build-crate.outputs.file-path }} + + - name: Publish archives and packages + uses: softprops/action-gh-release@v1 + with: + files: | + ${{ steps.build-crate.outputs.file-path }} + if: startsWith(github.ref, 'refs/tags/') + + publish: + runs-on: ubuntu-latest + needs: build_release + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: '1.13.4' # Define the elixir version [required] + otp-version: '25.3' # Define the OTP version [required] + - name: Install dependencies + run: | + mix deps.get + # workaround error for metadata about current target for the module Mediasoup.Nif is not available. + mix compile --force || true + + - name: download checksum files + run: mix rustler_precompiled.download Mediasoup.Nif --all + + - name: publish to hex + run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} \ No newline at end of file diff --git a/lib/nif.ex b/lib/nif.ex index 5a23c61..b45303a 100644 --- a/lib/nif.ex +++ b/lib/nif.ex @@ -1,5 +1,15 @@ defmodule Yex.Nif do - use Rustler, otp_app: :y_ex, crate: "yex" + + version = Mix.Project.config()[:version] + + use RustlerPrecompiled, + otp_app: :y_ex, + crate: "yex", + base_url: + "https://github.com/satoren/y_ex/releases/download/v#{version}", + force_build: System.get_env("RUSTLER_PRECOMPILATION_YEX_BUILD") in ["1", "true"], + version: version + def doc_new(), do: :erlang.nif_error(:nif_not_loaded) def doc_with_options(_option), do: :erlang.nif_error(:nif_not_loaded) diff --git a/mix.exs b/mix.exs index a164a6d..a51d4e7 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Yex.MixProject do use Mix.Project - @version "0.0.1" + @version "0.0.2" @repo "https://github.com/satoren/y_ex" @description """ @@ -17,7 +17,9 @@ defmodule Yex.MixProject do package: package(), name: "y_ex", description: @description, - deps: deps() + deps: deps(), + source_url: @repo, + homepage_url: @repo ] end @@ -38,6 +40,7 @@ defmodule Yex.MixProject do "priv", "native", "README.md", + "checksum-*.exs", "mix.exs" ], exclude_files: ["test", "native/target", "native/*.so"] @@ -46,7 +49,8 @@ defmodule Yex.MixProject do defp deps do [ - {:rustler, "~> 0.33.0"}, + {:rustler, ">= 0.0.0", optional: true}, + {:rustler_precompiled, "~> 0.7"}, {:ex_doc, "~> 0.29", only: :dev, runtime: false} ] end diff --git a/mix.lock b/mix.lock index 9db92a8..0eb40bd 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,5 @@ %{ + "castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"}, "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, "jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"}, @@ -7,5 +8,6 @@ "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "rustler": {:hex, :rustler, "0.33.0", "4a5b0a7a7b0b51549bea49947beff6fae9bc5d5326104dcd4531261e876b5619", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "7c4752728fee59a815ffd20c3429c55b644041f25129b29cdeb5c470b80ec5fd"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.7.2", "097f657e401f02e7bc1cab808cfc6abdc1f7b9dc5e5adee46bf2fd8fdcce9ecf", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "7663faaeadc9e93e605164dcf9e69168e35f2f8b7f2b9eb4e400d1a8e0fe2999"}, "toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"}, } diff --git a/native/yex/.cargo/config.toml b/native/yex/.cargo/config.toml index 20f03f3..8bd97f9 100644 --- a/native/yex/.cargo/config.toml +++ b/native/yex/.cargo/config.toml @@ -1,5 +1,26 @@ -[target.'cfg(target_os = "macos")'] +[target.x86_64-apple-darwin] rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", ] + +[target.aarch64-apple-darwin] +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" +] + +# See https://github.com/rust-lang/rust/issues/59302 +[target.aarch64-unknown-linux-musl] +rustflags = [ + "-C", "target-feature=-crt-static" +] + +[profile.release] +lto = true \ No newline at end of file diff --git a/native/yex/Cargo.toml b/native/yex/Cargo.toml index d652a31..e2f6c25 100644 --- a/native/yex/Cargo.toml +++ b/native/yex/Cargo.toml @@ -13,3 +13,9 @@ crate-type = ["cdylib"] rustler = "0.34.0" scoped_thread_local = "0.5.1" yrs = "0.18.8" + +[features] +default = ["nif_version_2_15"] +nif_version_2_15 = ["rustler/nif_version_2_15"] +nif_version_2_16 = ["rustler/nif_version_2_16"] +nif_version_2_17 = ["rustler/nif_version_2_17"] \ No newline at end of file diff --git a/native/yex/Cross.toml b/native/yex/Cross.toml new file mode 100644 index 0000000..ea92ea7 --- /dev/null +++ b/native/yex/Cross.toml @@ -0,0 +1,4 @@ +[build.env] +passthrough = [ + "RUSTLER_NIF_VERSION" +] \ No newline at end of file