Skip to content

Commit

Permalink
WIP build: precompiled
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Oct 25, 2023
1 parent 80b39ee commit 5af6865
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/candlex/native.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
defmodule Candlex.Native do
@moduledoc false

use Rustler, otp_app: :candlex, features: Application.compile_env(:candlex, :crate_features, [])
version = Mix.Project.config()[:version]
source_url = "https://github.com/mimiquate/candlex"

use RustlerPrecompiled,
otp_app: :candlex,
features: Application.compile_env(:candlex, :crate_features, []),
base_url: "#{source_url}/releases/download/v#{version}",
force_build: System.get_env("BUILD") in ["1", "true"],
version: version

# Rustler will override all the below stub functions with real NIFs
def from_binary(_binary, _dtype, _shape, _device), do: error()
Expand Down
16 changes: 13 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ defmodule Candlex.MixProject do
defp deps do
[
{:nx, "~> 0.6.2"},
{:rustler, "~> 0.30.0"},
{:rustler_precompiled, "~> 0.7.0"},

# Dev
{:ex_doc, "~> 0.30.9", only: :dev, runtime: false}
{:ex_doc, "~> 0.30.9", only: :dev, runtime: false},
{:rustler, "~> 0.30.0", optional: true}
]
end

Expand All @@ -50,7 +51,16 @@ defmodule Candlex.MixProject do

defp package do
[
files: ["lib", "native", "priv", ".formatter.exs", "mix.exs", "README.md", "LICENSE"],
files: [
"lib",
"native",
"priv",
".formatter.exs",
"mix.exs",
"README.md",
"LICENSE",
"checksum-*.exs"
],
licenses: ["Apache-2.0"],
links: %{
"GitHub" => @source_url
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.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"},
"complex": {:hex, :complex, "0.5.0", "af2d2331ff6170b61bb738695e481b27a66780e18763e066ee2cd863d0b1dd92", [:mix], [], "hexpm", "2683bd3c184466cfb94fad74cbfddfaa94b860e27ad4ca1bffe3bff169d91ef1"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
"ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"},
Expand All @@ -9,6 +10,7 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"nx": {:hex, :nx, "0.6.2", "f1d137f477b1a6f84f8db638f7a6d5a0f8266caea63c9918aa4583db38ebe1d6", [:mix], [{:complex, "~> 0.5", [hex: :complex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ac913b68d53f25f6eb39bddcf2d2cd6ea2e9bcb6f25cf86a79e35d0411ba96ad"},
"rustler": {:hex, :rustler, "0.30.0", "cefc49922132b072853fa9b0ca4dc2ffcb452f68fb73b779042b02d545e097fb", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "9ef1abb6a7dda35c47cfc649e6a5a61663af6cf842a55814a554a84607dee389"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.7.0", "5d0834fc06dbc76dd1034482f17b1797df0dba9b491cef8bb045fcaca94bcade", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "fdf43a6835f4e4de5bfbc4c019bfb8c46d124bd4635fefa3e20d9a2bbbec1512"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
}
10 changes: 10 additions & 0 deletions native/candlex/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ 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
2 changes: 1 addition & 1 deletion native/candlex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib"]
candle-core = { git = "https://github.com/huggingface/candle" }
half = "2.3.1"
num-traits = "0.2.17"
rustler = "0.30.0"
rustler = { version = "0.30.0", default-features = false, features = ["derive", "nif_version_2_16"] }
statrs = "0.16.0"
thiserror = "1.0.50"

Expand Down

0 comments on commit 5af6865

Please sign in to comment.