From d761aef39a3f68f45343f13f8916e9730465220b Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Thu, 21 Mar 2024 09:36:11 +0100 Subject: [PATCH] Drop deprecated functionality --- Cargo.toml | 1 - rustler/src/export.rs | 148 ------------------ rustler/src/lib.rs | 1 - rustler/src/resource.rs | 8 - rustler/src/types/atom.rs | 38 ----- rustler/src/types/mod.rs | 8 - rustler_mix/lib/mix/tasks/compile.rustler.ex | 19 --- rustler_mix/lib/rustler/compiler/config.ex | 21 --- rustler_tests/lib/deprecated_macros.ex | 7 - .../native/deprecated_macros/Cargo.toml | 13 -- .../native/deprecated_macros/src/lib.rs | 33 ---- 11 files changed, 297 deletions(-) delete mode 100644 rustler/src/export.rs delete mode 100644 rustler_mix/lib/mix/tasks/compile.rustler.ex delete mode 100644 rustler_tests/lib/deprecated_macros.ex delete mode 100644 rustler_tests/native/deprecated_macros/Cargo.toml delete mode 100644 rustler_tests/native/deprecated_macros/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index bebd1858..7f43e19e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ members = [ "rustler_tests/native/rustler_test", "rustler_tests/native/rustler_bigint_test", "rustler_tests/native/rustler_serde_test", - "rustler_tests/native/deprecated_macros", "rustler_tests/native/dynamic_load", "rustler_tests/native/rustler_compile_tests", "rustler_benchmarks/native/benchmark", diff --git a/rustler/src/export.rs b/rustler/src/export.rs deleted file mode 100644 index 48aa2648..00000000 --- a/rustler/src/export.rs +++ /dev/null @@ -1,148 +0,0 @@ -/// Exports a given list of functions to a Erlang module. -/// -/// This should be called exactly once in every NIF library. It will wrap and export the given rust -/// functions into the Erlang module. -/// -/// The first argument is a string specifying what Erlang/Elixir module you want the function -/// exported into. In Erlang this will simply be the atom you named your module. In Elixir, all -/// modules are prefixed with `Elixir.` -/// -/// The second argument is a list of 3-tuples. Each tuple contains information on a single exported -/// NIF function. The first tuple item is the name you want to export the function into, the second -/// is the arity (number of arguments) of the exported function. The third argument is a -/// identifier of a rust function. This is where your actual NIF will be implemented. -/// -/// The third argument is an `Option bool>`. If this is -/// `Some`, the function will execute when the NIF is first loaded by the BEAM. -#[macro_export] -#[deprecated(since = "0.22.0", note = "Please use `rustler::init!` instead.")] -macro_rules! rustler_export_nifs { - // Strip trailing comma. - ($name:expr, [$( $exported_nif:tt ),+,], $on_load:expr) => { - $crate::rustler_export_nifs!($name, [$( $exported_nif ),*], $on_load); - }; - ($name:expr, [$( $exported_nif:tt ),*], $on_load:expr) => { - static mut NIF_ENTRY: Option<$crate::codegen_runtime::DEF_NIF_ENTRY> = None; - - $crate::rustler_export_nifs!(internal_platform_init, ({ - // TODO: If an unwrap ever happens, we will unwind right into C! Fix this! - - extern "C" fn nif_load( - env: $crate::codegen_runtime::NIF_ENV, - _priv_data: *mut *mut $crate::codegen_runtime::c_void, - load_info: $crate::codegen_runtime::NIF_TERM) - -> $crate::codegen_runtime::c_int { - unsafe { - $crate::codegen_runtime::handle_nif_init_call($on_load, env, load_info) - } - } - - const FUN_ENTRIES: &'static [$crate::codegen_runtime::DEF_NIF_FUNC] = &[ - $($crate::rustler_export_nifs!(internal_item_init, $exported_nif)),* - ]; - - let entry = $crate::codegen_runtime::DEF_NIF_ENTRY { - major: $crate::codegen_runtime::NIF_MAJOR_VERSION, - minor: $crate::codegen_runtime::NIF_MINOR_VERSION, - name: concat!($name, "\x00") as *const str as *const $crate::codegen_runtime::c_char, - num_of_funcs: FUN_ENTRIES.len() as $crate::codegen_runtime::c_int, - funcs: FUN_ENTRIES.as_ptr(), - load: Some(nif_load), - reload: None, - upgrade: None, - unload: None, - vm_variant: b"beam.vanilla\x00".as_ptr() as *const $crate::codegen_runtime::c_char, - options: 0, - sizeof_ErlNifResourceTypeInit: $crate::codegen_runtime::get_nif_resource_type_init_size(), - }; - unsafe { NIF_ENTRY = Some(entry) }; - - unsafe { NIF_ENTRY.as_ref().unwrap() } - })); - }; - - (internal_item_init, ($nif_name:expr, $nif_arity:expr, $nif_fun:path)) => { - $crate::rustler_export_nifs!(internal_item_init, ($nif_name, $nif_arity, $nif_fun, $crate::schedule::SchedulerFlags::Normal)) - }; - (internal_item_init, ($nif_name:expr, $nif_arity:expr, $nif_fun:path, $nif_flag:expr)) => { - $crate::codegen_runtime::DEF_NIF_FUNC { - name: concat!($nif_name, "\x00") as *const str as *const $crate::codegen_runtime::c_char, - arity: $nif_arity, - function: { - extern "C" fn nif_func( - env: $crate::codegen_runtime::NIF_ENV, - argc: $crate::codegen_runtime::c_int, - argv: *const $crate::codegen_runtime::NIF_TERM) - -> $crate::codegen_runtime::NIF_TERM { - unsafe { - $crate::rustler_export_nifs!( - internal_handle_nif_call, ($nif_fun, $nif_arity, env, argc, argv)) - } - } - nif_func - }, - flags: ($nif_flag as $crate::schedule::SchedulerFlags) as u32, - } - }; - - (internal_handle_nif_call, ($fun:path, $arity:expr, $env:expr, $argc:expr, $argv:expr)) => ({ - use $crate::Term; - let env_lifetime = (); - let env = $crate::Env::new(&env_lifetime, $env); - - let terms = ::std::slice::from_raw_parts($argv, $argc as usize) - .iter() - .map(|x| $crate::Term::new(env, *x)) - .collect::>(); - - let result: ::std::thread::Result<_> = ::std::panic::catch_unwind(move || { - $crate::codegen_runtime::NifReturnable::into_returned($fun(env, &terms), env) - }); - - match result { - Ok(res) => res.apply(env), - Err(_err) => $crate::codegen_runtime::raise_exception( - env.as_c_arg(), - $crate::types::atom::Atom::from_bytes(env, b"nif_panic").ok().unwrap().as_c_arg(), - ), - } - }); - - (internal_platform_init, ($inner:expr)) => { - #[cfg(not(feature = "alternative_nif_init_name"))] - #[cfg(unix)] - #[no_mangle] - extern "C" fn nif_init() -> *const $crate::codegen_runtime::DEF_NIF_ENTRY { - $inner - } - - #[cfg(not(feature = "alternative_nif_init_name"))] - #[cfg(windows)] - #[no_mangle] - extern "C" fn nif_init(callbacks: *mut $crate::codegen_runtime::TWinDynNifCallbacks) -> *const $crate::codegen_runtime::DEF_NIF_ENTRY { - unsafe { - $crate::codegen_runtime::WIN_DYN_NIF_CALLBACKS = Some(*callbacks); - } - - $inner - } - - #[cfg(feature = "alternative_nif_init_name")] - #[cfg(unix)] - #[no_mangle] - extern "C" fn rustler_nif_init() -> *const $crate::codegen_runtime::DEF_NIF_ENTRY { - $inner - } - - #[cfg(feature = "alternative_nif_init_name")] - #[cfg(windows)] - #[no_mangle] - extern "C" fn rustler_nif_init(callbacks: *mut $crate::codegen_runtime::TWinDynNifCallbacks) -> *const $crate::codegen_runtime::DEF_NIF_ENTRY { - unsafe { - $crate::codegen_runtime::WIN_DYN_NIF_CALLBACKS = Some(*callbacks); - } - - $inner - } - }; -} diff --git a/rustler/src/lib.rs b/rustler/src/lib.rs index 356bee86..2efc7159 100644 --- a/rustler/src/lib.rs +++ b/rustler/src/lib.rs @@ -60,7 +60,6 @@ pub mod thread; pub use crate::thread::{spawn, JobSpawner, ThreadSpawner}; pub mod error; -pub mod export; pub use crate::error::Error; pub mod r#return; diff --git a/rustler/src/resource.rs b/rustler/src/resource.rs index 89e83cd5..fb442f5d 100644 --- a/rustler/src/resource.rs +++ b/rustler/src/resource.rs @@ -261,14 +261,6 @@ where } } -#[macro_export] -#[deprecated(since = "0.22.0", note = "Please use `resource!` instead.")] -macro_rules! resource_struct_init { - ($struct_name:ty, $env: ident) => { - $crate::resource!($struct_name, $env) - }; -} - #[macro_export] macro_rules! resource { ($struct_name:ty, $env: ident) => { diff --git a/rustler/src/types/atom.rs b/rustler/src/types/atom.rs index b51f2bf7..43628abb 100644 --- a/rustler/src/types/atom.rs +++ b/rustler/src/types/atom.rs @@ -226,44 +226,6 @@ macro_rules! atoms { }; } -#[macro_export] -#[deprecated(since = "0.22.0", note = "Please use `atoms!` instead.")] -macro_rules! rustler_atoms { - { - $( - $( #[$attr:meta] )* - atom $name:ident $( = $str:expr )?; - )* - } => { - #[allow(non_snake_case)] - struct RustlerAtoms { - $( $name : $crate::types::atom::Atom ),* - } - $crate::lazy_static::lazy_static! { - static ref RUSTLER_ATOMS: RustlerAtoms = $crate::env::OwnedEnv::new().run(|env| { - RustlerAtoms { - $( $name: $crate::rustler_atoms!(@internal_make_atom(env, $name $( = $str)? )) ),* - } - }); - } - $( - $( #[$attr] )* - pub fn $name() -> $crate::types::atom::Atom { - RUSTLER_ATOMS.$name - } - )* - }; - - // Internal helper macros. - { @internal_make_atom($env:ident, $name:ident) } => { - $crate::rustler_atoms!(@internal_make_atom($env, $name = stringify!($name))) - }; - { @internal_make_atom($env:ident, $name:ident = $str:expr) } => { - $crate::types::atom::Atom::from_str($env, $str) - .expect("rustler::atoms!: bad atom string") - }; -} - atoms! { /// The `nif_panicked` atom. nif_panicked, diff --git a/rustler/src/types/mod.rs b/rustler/src/types/mod.rs index 9a5c78a7..f5eb0cc6 100644 --- a/rustler/src/types/mod.rs +++ b/rustler/src/types/mod.rs @@ -31,14 +31,6 @@ pub mod tuple; pub mod local_pid; pub use self::local_pid::LocalPid; -#[deprecated(since = "0.22.0", note = "Please use local_pid instead")] -pub mod pid { - #[deprecated(since = "0.22.0", note = "Please use LocalPid instead")] - pub use super::LocalPid as Pid; -} -#[deprecated(since = "0.22.0", note = "Please use LocalPid instead")] -pub use self::LocalPid as Pid; - pub mod truthy; pub mod elixir_struct; diff --git a/rustler_mix/lib/mix/tasks/compile.rustler.ex b/rustler_mix/lib/mix/tasks/compile.rustler.ex deleted file mode 100644 index 3e01f68f..00000000 --- a/rustler_mix/lib/mix/tasks/compile.rustler.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Mix.Tasks.Compile.Rustler do - @moduledoc false - - use Mix.Task - - def run(_args) do - IO.puts([ - IO.ANSI.yellow(), - """ - - The `:rustler` compiler has been deprecated since v0.22.0 and will be - removed in v1.0. - - To remove this warning, please consult the CHANGELOG for v0.22.0. - """, - IO.ANSI.default_color() - ]) - end -end diff --git a/rustler_mix/lib/rustler/compiler/config.ex b/rustler_mix/lib/rustler/compiler/config.ex index dc508fe0..e51025f8 100644 --- a/rustler_mix/lib/rustler/compiler/config.ex +++ b/rustler_mix/lib/rustler/compiler/config.ex @@ -35,20 +35,6 @@ defmodule Rustler.Compiler.Config do def from(otp_app, config, opts) do crate = config[:crate] || opts[:crate] || otp_app - # TODO: Remove in 1.0 - rustler_crates = - if mix_config = Mix.Project.config()[:rustler_crates] do - IO.warn( - ":rustler_crates in mix.exs is deprecated, please explicitly pass options on `use Rustler` or configure the module in your `config/*.exs` files" - ) - - mix_config - else - [] - end - - legacy_config = rustler_crates[to_atom(crate)] || [] - defaults = %Config{ crate: crate, load_from: {otp_app, "priv/native/lib#{crate}"}, @@ -61,7 +47,6 @@ defmodule Rustler.Compiler.Config do defaults |> Map.from_struct() |> Enum.into([]) - |> Keyword.merge(legacy_config) |> Keyword.merge(opts) |> Keyword.merge(config) |> build() @@ -147,10 +132,4 @@ defmodule Rustler.Compiler.Config do |> Enum.filter(&(&1["name"] == name)) |> List.first() end - - defp to_atom(name) when is_binary(name), - do: String.to_atom(name) - - defp to_atom(name) when is_atom(name), - do: name end diff --git a/rustler_tests/lib/deprecated_macros.ex b/rustler_tests/lib/deprecated_macros.ex deleted file mode 100644 index b003fbb7..00000000 --- a/rustler_tests/lib/deprecated_macros.ex +++ /dev/null @@ -1,7 +0,0 @@ -defmodule DeprecatedMacros do - use Rustler, - otp_app: :rustler_test, - crate: :deprecated_macros - - def add(_, _), do: :erlang.nif_error(:deprecated_macros_not_loaded) -end diff --git a/rustler_tests/native/deprecated_macros/Cargo.toml b/rustler_tests/native/deprecated_macros/Cargo.toml deleted file mode 100644 index 39b6c5c1..00000000 --- a/rustler_tests/native/deprecated_macros/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "deprecated_macros" -version = "0.1.0" -authors = [] -edition = "2018" - -[lib] -name = "deprecated_macros" -path = "src/lib.rs" -crate-type = ["cdylib"] - -[dependencies] -rustler = { path = "../../../rustler" } diff --git a/rustler_tests/native/deprecated_macros/src/lib.rs b/rustler_tests/native/deprecated_macros/src/lib.rs deleted file mode 100644 index 0c147876..00000000 --- a/rustler_tests/native/deprecated_macros/src/lib.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![allow(deprecated)] -use rustler::{Encoder, Env, Error, Term}; - -mod atoms { - rustler::rustler_atoms! { - atom ok; - } -} - -#[allow(dead_code)] -struct TestResource { - a: u32, -} - -rustler::rustler_export_nifs! { - "Elixir.DeprecatedMacros", - [ - ("add", 2, add), - ], - Some(load) -} - -fn add<'a>(env: Env<'a>, terms: &[Term<'a>]) -> Result, Error> { - let a: u32 = terms[0].decode()?; - let b: u32 = terms[1].decode()?; - - Ok((atoms::ok(), a + b).encode(env)) -} - -fn load(env: Env, _: Term) -> bool { - rustler::resource_struct_init!(TestResource, env); - true -}