From af2557d29974bca9ae4a93cf5c57b1ec3179c0e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 26 Nov 2023 13:04:55 +0100 Subject: [PATCH 1/5] Modify the MDB_IDL_LOGN define when cc::Building --- lmdb-master-sys/Cargo.toml | 19 +++++++++++++++++++ lmdb-master-sys/bindgen.rs | 4 +--- lmdb-master-sys/build.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index a9a89268..2c713b98 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -40,3 +40,22 @@ asan = [] fuzzer = [] fuzzer-no-link = [] posix-sem = [] + +# These features configure the MDB_IDL_LOGN macro, which determines +# the size of the free and dirty page lists (and thus the amount of memory +# allocated when opening an LMDB environment in read-write mode). +# +# Each feature defines MDB_IDL_LOGN as the value in the name of the feature. +# That means these features are mutually exclusive, and you must not specify +# more than one at the same time (or the crate will fail to compile). +# +# For more information on the motivation for these features (and their effect), +# see https://github.com/mozilla/lmdb/pull/2. +mdb_idl_logn_8 = [] +mdb_idl_logn_9 = [] +mdb_idl_logn_10 = [] +mdb_idl_logn_11 = [] +mdb_idl_logn_12 = [] +mdb_idl_logn_13 = [] +mdb_idl_logn_14 = [] +mdb_idl_logn_15 = [] diff --git a/lmdb-master-sys/bindgen.rs b/lmdb-master-sys/bindgen.rs index 64b8339f..8717736c 100644 --- a/lmdb-master-sys/bindgen.rs +++ b/lmdb-master-sys/bindgen.rs @@ -70,7 +70,5 @@ pub fn generate() { .generate() .expect("Unable to generate bindings"); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); + bindings.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings!"); } diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index 8c49a510..bc41b99a 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -10,6 +10,34 @@ mod generate; use std::env; use std::path::PathBuf; +#[cfg(feature = "mdb_idl_logn_8")] +const MDB_IDL_LOGN: u8 = 8; +#[cfg(feature = "mdb_idl_logn_9")] +const MDB_IDL_LOGN: u8 = 9; +#[cfg(feature = "mdb_idl_logn_10")] +const MDB_IDL_LOGN: u8 = 10; +#[cfg(feature = "mdb_idl_logn_11")] +const MDB_IDL_LOGN: u8 = 11; +#[cfg(feature = "mdb_idl_logn_12")] +const MDB_IDL_LOGN: u8 = 12; +#[cfg(feature = "mdb_idl_logn_13")] +const MDB_IDL_LOGN: u8 = 13; +#[cfg(feature = "mdb_idl_logn_14")] +const MDB_IDL_LOGN: u8 = 14; +#[cfg(feature = "mdb_idl_logn_15")] +const MDB_IDL_LOGN: u8 = 15; +#[cfg(not(any( + feature = "mdb_idl_logn_8", + feature = "mdb_idl_logn_9", + feature = "mdb_idl_logn_10", + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", +)))] +const MDB_IDL_LOGN: u8 = 16; // default + macro_rules! warn { ($message:expr) => { println!("cargo:warning={}", $message); @@ -33,6 +61,7 @@ fn main() { let mut builder = cc::Build::new(); builder + .define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str())) .file(lmdb.join("mdb.c")) .file(lmdb.join("midl.c")) // https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 From 5bb58c1139a054268a4652131b9d4a129baf7357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 28 Nov 2023 16:38:48 +0100 Subject: [PATCH 2/5] Make cargo fmt happy --- lmdb-master-sys/bindgen.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lmdb-master-sys/bindgen.rs b/lmdb-master-sys/bindgen.rs index 8717736c..64b8339f 100644 --- a/lmdb-master-sys/bindgen.rs +++ b/lmdb-master-sys/bindgen.rs @@ -70,5 +70,7 @@ pub fn generate() { .generate() .expect("Unable to generate bindings"); - bindings.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings!"); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); } From 4af759c2b964fc2875198ba8f58b1519de920b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 2 Dec 2023 11:16:16 +0100 Subject: [PATCH 3/5] Introduce the default mdb_idl_logn_16 too --- lmdb-master-sys/Cargo.toml | 1 + lmdb-master-sys/build.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lmdb-master-sys/Cargo.toml b/lmdb-master-sys/Cargo.toml index 2c713b98..7e7ff6a6 100644 --- a/lmdb-master-sys/Cargo.toml +++ b/lmdb-master-sys/Cargo.toml @@ -59,3 +59,4 @@ mdb_idl_logn_12 = [] mdb_idl_logn_13 = [] mdb_idl_logn_14 = [] mdb_idl_logn_15 = [] +mdb_idl_logn_16 = [] diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index bc41b99a..af18c4d1 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -26,6 +26,8 @@ const MDB_IDL_LOGN: u8 = 13; const MDB_IDL_LOGN: u8 = 14; #[cfg(feature = "mdb_idl_logn_15")] const MDB_IDL_LOGN: u8 = 15; +#[cfg(feature = "mdb_idl_logn_16")] +const MDB_IDL_LOGN: u8 = 16; #[cfg(not(any( feature = "mdb_idl_logn_8", feature = "mdb_idl_logn_9", @@ -35,6 +37,7 @@ const MDB_IDL_LOGN: u8 = 15; feature = "mdb_idl_logn_13", feature = "mdb_idl_logn_14", feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16", )))] const MDB_IDL_LOGN: u8 = 16; // default From a68b0976c01593278f9ac49931b297d8e5b4bacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 2 Dec 2023 11:16:34 +0100 Subject: [PATCH 4/5] Expose the mdb_idl_logn features from heed --- heed/Cargo.toml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/heed/Cargo.toml b/heed/Cargo.toml index e10bfc30..990b3402 100644 --- a/heed/Cargo.toml +++ b/heed/Cargo.toml @@ -72,6 +72,26 @@ unbounded_depth = ["heed-types/unbounded_depth"] # posix-sem = ["lmdb-master-sys/posix-sem"] +# These features configure the MDB_IDL_LOGN macro, which determines +# the size of the free and dirty page lists (and thus the amount of memory +# allocated when opening an LMDB environment in read-write mode). +# +# Each feature defines MDB_IDL_LOGN as the value in the name of the feature. +# That means these features are mutually exclusive, and you must not specify +# more than one at the same time (or the crate will fail to compile). +# +# For more information on the motivation for these features (and their effect), +# see https://github.com/mozilla/lmdb/pull/2. +mdb_idl_logn_8 = ["lmdb-master-sys/mdb_idl_logn_8"] +mdb_idl_logn_9 = ["lmdb-master-sys/mdb_idl_logn_9"] +mdb_idl_logn_10 = ["lmdb-master-sys/mdb_idl_logn_10"] +mdb_idl_logn_11 = ["lmdb-master-sys/mdb_idl_logn_11"] +mdb_idl_logn_12 = ["lmdb-master-sys/mdb_idl_logn_12"] +mdb_idl_logn_13 = ["lmdb-master-sys/mdb_idl_logn_13"] +mdb_idl_logn_14 = ["lmdb-master-sys/mdb_idl_logn_14"] +mdb_idl_logn_15 = ["lmdb-master-sys/mdb_idl_logn_15"] +mdb_idl_logn_16 = ["lmdb-master-sys/mdb_idl_logn_16"] + [[example]] name = "rmp-serde" required-features = ["serde-rmp"] From 7e5ae1aaa764052f2d266013dc7694d01ee9ccad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 2 Dec 2023 11:34:38 +0100 Subject: [PATCH 5/5] Unify the mdb_idl_logn features to take the highest --- lmdb-master-sys/build.rs | 103 +++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 21 deletions(-) diff --git a/lmdb-master-sys/build.rs b/lmdb-master-sys/build.rs index af18c4d1..d3e7d18d 100644 --- a/lmdb-master-sys/build.rs +++ b/lmdb-master-sys/build.rs @@ -10,36 +10,97 @@ mod generate; use std::env; use std::path::PathBuf; -#[cfg(feature = "mdb_idl_logn_8")] +#[cfg(all( + feature = "mdb_idl_logn_8", + not(any( + feature = "mdb_idl_logn_9", + feature = "mdb_idl_logn_10", + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 8; -#[cfg(feature = "mdb_idl_logn_9")] +#[cfg(all( + feature = "mdb_idl_logn_9", + not(any( + feature = "mdb_idl_logn_10", + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 9; -#[cfg(feature = "mdb_idl_logn_10")] +#[cfg(all( + feature = "mdb_idl_logn_10", + not(any( + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 10; -#[cfg(feature = "mdb_idl_logn_11")] +#[cfg(all( + feature = "mdb_idl_logn_11", + not(any( + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 11; -#[cfg(feature = "mdb_idl_logn_12")] +#[cfg(all( + feature = "mdb_idl_logn_12", + not(any( + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 12; -#[cfg(feature = "mdb_idl_logn_13")] +#[cfg(all( + feature = "mdb_idl_logn_13", + not(any( + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16" + )) +))] const MDB_IDL_LOGN: u8 = 13; -#[cfg(feature = "mdb_idl_logn_14")] +#[cfg(all( + feature = "mdb_idl_logn_14", + not(any(feature = "mdb_idl_logn_15", feature = "mdb_idl_logn_16")) +))] const MDB_IDL_LOGN: u8 = 14; -#[cfg(feature = "mdb_idl_logn_15")] +#[cfg(all(feature = "mdb_idl_logn_15", not(any(feature = "mdb_idl_logn_16"))))] const MDB_IDL_LOGN: u8 = 15; -#[cfg(feature = "mdb_idl_logn_16")] -const MDB_IDL_LOGN: u8 = 16; -#[cfg(not(any( - feature = "mdb_idl_logn_8", - feature = "mdb_idl_logn_9", - feature = "mdb_idl_logn_10", - feature = "mdb_idl_logn_11", - feature = "mdb_idl_logn_12", - feature = "mdb_idl_logn_13", - feature = "mdb_idl_logn_14", - feature = "mdb_idl_logn_15", +#[cfg(any( feature = "mdb_idl_logn_16", -)))] -const MDB_IDL_LOGN: u8 = 16; // default + not(any( + feature = "mdb_idl_logn_8", + feature = "mdb_idl_logn_9", + feature = "mdb_idl_logn_10", + feature = "mdb_idl_logn_11", + feature = "mdb_idl_logn_12", + feature = "mdb_idl_logn_13", + feature = "mdb_idl_logn_14", + feature = "mdb_idl_logn_15", + feature = "mdb_idl_logn_16", + )) +))] +const MDB_IDL_LOGN: u8 = 16; macro_rules! warn { ($message:expr) => {