From 3ccd2d538f38d53310f6b2e11d33a26e1a002546 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Thu, 22 Jun 2023 03:21:31 +0200 Subject: [PATCH] Drop support for RUSTLER_NIF_VERSION --- CHANGELOG.md | 6 +++++ README.md | 3 --- build_common.rs | 55 ----------------------------------------- rustler/build.rs | 8 ------ rustler/build_common.rs | 1 - rustler_sys/build.rs | 12 +++------ 6 files changed, 10 insertions(+), 75 deletions(-) delete mode 100644 build_common.rs delete mode 100644 rustler/build.rs delete mode 120000 rustler/build_common.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c796143..6843742f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ See [`UPGRADE.md`](./UPGRADE.md) for additional help when upgrading to newer ver ## [unreleased] +### Added + +### Changed + +* Dropped support for `RUSTLER_NIF_VERSION` + ## [0.29.0] - 2023-06-22 ### Added diff --git a/README.md b/README.md index 0748d4da..dcbe6a82 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,6 @@ enabled on the dependency: rustler = { version = "...", features = ["nif_version_2_16"] } ``` -For compatibility reasons, this can be defined (and overridden) by setting the -`RUSTLER_NIF_VERSION` environment variable during build. - #### Community You can find us in the `#rustler:matrix.org` channel on [Matrix](https://matrix.to/#/#rustler:matrix.org) diff --git a/build_common.rs b/build_common.rs deleted file mode 100644 index acf48853..00000000 --- a/build_common.rs +++ /dev/null @@ -1,55 +0,0 @@ -mod common { - use std::env; - - pub const MIN_SUPPORTED_VERSION: (u32, u32) = (2, 14); - pub const MAX_SUPPORTED_VERSION: (u32, u32) = (2, 17); - - fn get_nif_version_from_env(version: &str) -> (u32, u32) { - let parts: Vec> = version - .split('.') - .take(2) - .map(|n| n.parse::()) - .collect(); - - let mut nif_version = match &parts[..] { - [Ok(major), Ok(minor)] => (*major, *minor), - _other => panic!("The RUSTLER_NIF_VERSION is not a valid version"), - }; - - if nif_version < MIN_SUPPORTED_VERSION { - panic!( - "The NIF version given from RUSTLER_NIF_VERSION is not supported: {}.{}", - nif_version.0, nif_version.1 - ); - } - - // TODO: This code will need adjustment if the Erlang developers ever decide to introduce - // a new major NIF version. - if nif_version > MAX_SUPPORTED_VERSION { - eprintln!( - "NIF version {}.{} is not yet supported, falling back to {}.{}", - nif_version.0, nif_version.1, MAX_SUPPORTED_VERSION.0, MAX_SUPPORTED_VERSION.1 - ); - nif_version = MAX_SUPPORTED_VERSION; - } - - nif_version - } - - pub fn handle_nif_version_from_env() -> Option<(u32, u32)> { - println!("cargo:rerun-if-env-changed=RUSTLER_NIF_VERSION"); - env::var("RUSTLER_NIF_VERSION").ok().map(|val| { - let nif_version = get_nif_version_from_env(&val); - - // Activate all config flags for the supported NIF versions - for minor in 0..=nif_version.1 { - println!( - "cargo:rustc-cfg=feature=\"nif_version_{}_{}\"", - nif_version.0, minor - ); - } - - nif_version - }) - } -} diff --git a/rustler/build.rs b/rustler/build.rs deleted file mode 100644 index 8da1cefd..00000000 --- a/rustler/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -include!("build_common.rs"); - -fn main() { - common::handle_nif_version_from_env(); - - // The following lines are important to tell Cargo to recompile if something changes. - println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/rustler/build_common.rs b/rustler/build_common.rs deleted file mode 120000 index 89a82cd7..00000000 --- a/rustler/build_common.rs +++ /dev/null @@ -1 +0,0 @@ -../build_common.rs \ No newline at end of file diff --git a/rustler_sys/build.rs b/rustler_sys/build.rs index af48aefb..98ba5ed9 100644 --- a/rustler_sys/build.rs +++ b/rustler_sys/build.rs @@ -2,16 +2,15 @@ // // Generate the NIF APIs that will be built in `src/rustler_sys_api.rs`. // -// This script rely on the `RUSTLER_NIF_VERSION` environment variable -// and will fallback to the installed OTP version to detect the version. -// If none of them are available, then we are going to use the latest version. -// use regex::Regex; use std::fmt::Write; use std::path::Path; use std::{env, fs}; +pub const MIN_SUPPORTED_VERSION: (u32, u32) = (2, 14); +pub const MAX_SUPPORTED_VERSION: (u32, u32) = (2, 17); + const SNIPPET_NAME: &str = "nif_api.snippet"; trait ApiBuilder { @@ -880,9 +879,6 @@ fn build_api(b: &mut dyn ApiBuilder, opts: &GenerateOptions) { } } -include!("build_common.rs"); -use common::*; - fn get_nif_version_from_features() -> (u32, u32) { for major in ((MIN_SUPPORTED_VERSION.0)..=(MAX_SUPPORTED_VERSION.0)).rev() { for minor in ((MIN_SUPPORTED_VERSION.1)..=(MAX_SUPPORTED_VERSION.1)).rev() { @@ -898,7 +894,7 @@ fn get_nif_version_from_features() -> (u32, u32) { } fn main() { - let nif_version = handle_nif_version_from_env().unwrap_or_else(get_nif_version_from_features); + let nif_version = get_nif_version_from_features(); let target_family = if cfg!(target_family = "windows") { OsFamily::Win