Skip to content

Commit

Permalink
setup rustler precompiled
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren committed Jul 20, 2024
1 parent 2193d9b commit 442efed
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

name: Elixir CI

env:
MIX_ENV: test
RUSTLER_PRECOMPILATION_YEX_BUILD: "true"

on:
push:
branches: [ "main" ]
Expand Down
94 changes: 94 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
12 changes: 11 additions & 1 deletion lib/nif.ex
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -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 """
Expand All @@ -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

Expand All @@ -38,6 +40,7 @@ defmodule Yex.MixProject do
"priv",
"native",
"README.md",
"checksum-*.exs",
"mix.exs"
],
exclude_files: ["test", "native/target", "native/*.so"]
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -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"},
Expand All @@ -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"},
}
27 changes: 24 additions & 3 deletions native/yex/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions native/yex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 4 additions & 0 deletions native/yex/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build.env]
passthrough = [
"RUSTLER_NIF_VERSION"
]

0 comments on commit 442efed

Please sign in to comment.