Skip to content

Commit

Permalink
Update and upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ericentin committed Apr 29, 2023
1 parent 2a84b30 commit 7e6ea34
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 74 deletions.
63 changes: 62 additions & 1 deletion lib/sled/native.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
defmodule Sled.Native do
@moduledoc false

use Rustler, otp_app: :sled, crate: :sled_nif
defmodule Helpers do
@moduledoc false

def rustc_mode(:prod), do: :release
def rustc_mode(_), do: :debug

def features do
if Application.get_env(:sled, :io_uring, false) or io_uring_supported?() do
["io_uring"]
else
[]
end
end

defp io_uring_supported?() do
is_linux?() and cargo_present?() and io_uring_test_success?()
end

defp is_linux? do
:os.type() == {:unix, :linux}
end

defp cargo_present? do
not is_nil(System.find_executable("cargo"))
end

defp io_uring_test_success? do
case System.cmd("cargo", ["run"],
stderr_to_stdout: true,
cd: Path.join([__DIR__, "..", "..", "native", "io_uring_test"])
) do
{_, 0} ->
true

{_, 1} ->
false

{stdout, exit_status} ->
io_uring_detection_error(stdout, exit_status)

false
end
end

defp io_uring_detection_error(stdout, exit_status) do
Mix.Shell.IO.error([
"""
Unexpected error determining if io_uring should be enabled.
Please open an issue at #{Mix.Project.config()[:package][:links]["GitHub"]} and include the following log. Thanks!
stdout:
""",
stdout,
"exited with status: #{exit_status}"
])
end
end

use Rustler,
otp_app: :sled,
crate: :sled_nif,
mode: Helpers.rustc_mode(Mix.env()),
features: Helpers.features()

def sled_config_new(_options), do: error()
def sled_config_open(_config), do: error()
Expand Down
64 changes: 2 additions & 62 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ defmodule Sled.MixProject do
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps(),
compilers: [:rustler] ++ Mix.compilers(),
rustler_crates: [
sled_nif: [
mode: rustc_mode(Mix.env()),
features: features()
]
],
description: description(),
package: package(),
source_url: "https://github.com/ericentin/sled",
Expand All @@ -36,8 +29,8 @@ defmodule Sled.MixProject do

defp deps do
[
{:rustler, "~> 0.22.0-rc.0"},
{:ex_doc, "~> 0.14", only: :dev, runtime: false}
{:rustler, "~> 0.28"},
{:ex_doc, "~> 0.29", only: :dev, runtime: false}
]
end

Expand Down Expand Up @@ -69,57 +62,4 @@ defmodule Sled.MixProject do
}
]
end

defp rustc_mode(:prod), do: :release
defp rustc_mode(_), do: :debug

def features do
if Application.get_env(:sled, :io_uring, false) or io_uring_supported?() do
["io_uring"]
else
[]
end
end

defp io_uring_supported?() do
is_linux?() and cargo_present?() and io_uring_test_success?()
end

defp is_linux? do
:os.type() == {:unix, :linux}
end

defp cargo_present? do
not is_nil(System.find_executable("cargo"))
end

defp io_uring_test_success? do
case System.cmd("cargo", ["run"],
stderr_to_stdout: true,
cd: Path.join([__DIR__, "native", "io_uring_test"])
) do
{_, 0} ->
true

{_, 1} ->
false

{stdout, exit_status} ->
io_uring_detection_error(stdout, exit_status)

false
end
end

defp io_uring_detection_error(stdout, exit_status) do
Mix.Shell.IO.error([
"""
Unexpected error determining if io_uring should be enabled.
Please open an issue at #{@sled_github_url} and include the following log. Thanks!
stdout:
""",
stdout,
"exited with status: #{exit_status}"
])
end
end
16 changes: 9 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
%{
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"ex_doc": {:hex, :ex_doc, "0.22.2", "03a2a58bdd2ba0d83d004507c4ee113b9c521956938298eba16e55cc4aba4a6c", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "cf60e1b3e2efe317095b6bb79651f83a2c1b3edcb4d319c421d7fcda8b3aff26"},
"makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
"nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"},
"rustler": {:hex, :rustler, "0.22.0-rc.0", "d8a3d72862874d6c5a5c6421617911e8a2822a310b6e6d3ceb16803c2651350f", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "0548ae8fd203bbd3c5ba689e60d827a1991e12cde599fb4c03d4cf56b00a3352"},
"toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"},
"earmark_parser": {:hex, :earmark_parser, "1.4.32", "fa739a0ecfa34493de19426681b23f6814573faee95dfd4b4aafe15a7b5b32c6", [:mix], [], "hexpm", "b8b0dd77d60373e77a3d7e8afa598f325e49e8663a51bcc2b88ef41838cca755"},
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [: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", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.0", "9e18a119d9efc3370a3ef2a937bf0b24c088d9c4bf0ba9d7c3751d49d347d035", [:mix], [], "hexpm", "7977f183127a7cbe9346981e2f480dc04c55ffddaef746bd58debd566070eef8"},
"rustler": {:hex, :rustler, "0.28.0", "b8e2c43013e12dd06f61dcf87033d2e2c8245feddb121b82179c923be31ad319", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "99f811f58c993f0343851adb0af589a99cfd3dc20f2efb8ef08d1a8447980b98"},
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
}
2 changes: 1 addition & 1 deletion native/io_uring_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "io_uring_test"
version = "0.1.0-alpha.2"
authors = ["Eric Entin <eric@ericent.in>"]
edition = "2018"
edition = "2021"

[dependencies]
rio = "^0.9.2"
4 changes: 2 additions & 2 deletions native/sled_nif/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "sled_nif"
version = "0.1.0-alpha.2"
authors = ["Eric Entin <eric@ericent.in>"]
edition = "2018"
edition = "2021"

[features]
io_uring = ["sled/io_uring"]
Expand All @@ -13,6 +13,6 @@ path = "src/lib.rs"
crate-type = ["dylib"]

[dependencies]
rustler = "^0.22.0-rc"
rustler = "^0.28.0"
lazy_static = "^1"
sled = "^0"
2 changes: 1 addition & 1 deletion test/sled_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule SledTest do

test "open invalid db_path" do
assert_raise ErlangError,
~r/Erlang error: \"sled::Error::Io\(Custom { kind: InvalidInput, error: .*/,
~r/Erlang error: \"sled::Error::Io\(Error { kind: InvalidInput, message: .*/,
fn -> Sled.open("\0") end
end

Expand Down

0 comments on commit 7e6ea34

Please sign in to comment.