Skip to content

Commit 7a8c436

Browse files
committed
Try releasing new rust revision
1 parent 1256eaf commit 7a8c436

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ dev:
1717
build:
1818
mix template_assets && mix phx.digest
1919

20+
cargo_build:
21+
cd native/componentsguide_rustler_math/ && cargo build --release
22+
2023
clean:
2124
rm -rf ./_build
2225

lib/components_guide/rustler/math.ex

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
defmodule ComponentsGuide.Rustler.Math do
2-
# use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math
3-
# use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math, target_dir: System.tmp_dir!()
4-
# use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math, cargo: {:rustup, :stable}
2+
if Mix.env() == :dev do
3+
use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math
4+
# use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math, target_dir: System.tmp_dir!()
5+
# use Rustler, otp_app: :components_guide, crate: :componentsguide_rustler_math, cargo: {:rustup, :stable}
6+
end
57

6-
app = Mix.Project.config()[:app]
7-
version = Mix.Project.config()[:version]
8+
if Mix.env() == :prod do
9+
app = Mix.Project.config()[:app]
10+
version = Mix.Project.config()[:version]
811

9-
use RustlerPrecompiled,
10-
otp_app: app,
11-
crate: "componentsguide_rustler_math",
12-
base_url:
13-
"https://github.com/ComponentsGuide/components_guide/releases/download/v#{version}",
14-
force_build: System.get_env("RUSTLER_PRECOMPILATION_EXAMPLE_BUILD") in ["1", "true"],
15-
version: version
12+
use RustlerPrecompiled,
13+
otp_app: app,
14+
crate: "componentsguide_rustler_math",
15+
base_url: "https://github.com/ComponentsGuide/components_guide/releases/download/v#{version}",
16+
force_build: System.get_env("RUSTLER_PRECOMPILATION_EXAMPLE_BUILD") in ["1", "true"],
17+
version: version
18+
end
1619

1720
def add(_, _), do: error()
21+
def reverse_string(_), do: error()
1822

1923
defp error, do: :erlang.nif_error(:nif_not_loaded)
2024
end

lib/components_guide_web/templates/cheatsheets/intro.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Various cheatsheets will be added over time. If you have ideas for cheatsheets,
22

33
<p><%= 6 + 1 %></p>
44
<p><%= ComponentsGuide.Rustler.Math.add(5, 9) %></p>
5+
<p><%= ComponentsGuide.Rustler.Math.reverse_string("hello") %></p>

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule ComponentsGuide.MixProject do
22
use Mix.Project
33

4-
@version "0.1.0"
4+
@version "0.1.1"
55

66
def project do
77
[

native/componentsguide_rustler_math/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@ fn add(a: i64, b: i64) -> i64 {
33
a + b
44
}
55

6-
rustler::init!("Elixir.ComponentsGuide.Rustler.Math", [add]);
6+
#[rustler::nif]
7+
fn reverse_string(a: String) -> String {
8+
// return a;
9+
return a.chars().rev().collect();
10+
}
11+
12+
rustler::init!("Elixir.ComponentsGuide.Rustler.Math", [add, reverse_string]);

0 commit comments

Comments
 (0)