From e05a9b3d47d1f305dd070e234bacf36e1c625021 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Sun, 3 Nov 2019 20:32:22 +0000 Subject: [PATCH 01/17] Can initialize, yay --- .gitignore | 3 +++ Cargo.toml | 11 ++++++++ build.rs | 51 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index c30610f..67313d4 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,6 @@ ThirdParty/stxxl .idea/* build/* + +Cargo.lock +target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3d3f675 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "mqf" +version = "0.1.0" +authors = ["Luiz Irber "] +links = "libmqf" + +[build-dependencies] +bindgen = "0.51" +cmake = "0.1.42" + +[dependencies] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c6b3f22 --- /dev/null +++ b/build.rs @@ -0,0 +1,51 @@ +use std::env; +use std::path::PathBuf; + +extern crate cmake; +use cmake::Config; + +fn main() { + let dst = Config::new(".") + .define("BUILD_STATIC_LIBS", "ON") + .define("CMAKE_BUILD_TYPE", "Release") + .build(); + + let target = env::var("TARGET").unwrap(); + if target.contains("apple") { + println!("cargo:rustc-link-lib=dylib=c++"); + } else if target.contains("linux") { + println!("cargo:rustc-link-lib=dylib=stdc++"); + } else { + unimplemented!(); + } + + println!("cargo:rustc-link-search=native={}/build/src", dst.display()); + println!( + "cargo:rustc-link-search=native={}/build/ThirdParty/stxxl/lib", + dst.display() + ); + + println!("cargo:rustc-link-lib=static=MQF"); + println!("cargo:rustc-link-lib=static=stxxl"); + + let bindings = bindgen::Builder::default() + .clang_arg("-I./include") + //.clang_arg("-I./ThirdParty/stxxl/include/stxxl") + //.clang_arg("-I./ThirdParty/stxxl/include") + .clang_arg("-x") + .clang_arg("c++") + .clang_arg("-std=c++11") + .header("include/gqf.h") + .whitelist_type("QF") + .whitelist_function("qf_*") + .whitelist_function("qf_init") + .blacklist_type("std::*") + //.opaque_type("QF") + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("couldn't write bindings!"); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ab09501 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,77 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::CString; + use std::ptr; + + #[test] + fn simple_counting_test() { + //except first item is inserted 5 times to full test _insert1 + let mut qf: QF = QF { + mem: ptr::null_mut(), + metadata: ptr::null_mut(), + blocks: ptr::null_mut(), + }; + + let counter_size = 2; + let qbits = 5; + let num_hash_bits = qbits + 8; + let maximum_count = (1u64 << counter_size) - 1; + let mut count = 0; + let mut fixed_counter = 0; + + let s = CString::new("").unwrap(); + + //INFO("Counter size = "< Date: Mon, 4 Nov 2019 00:36:34 +0000 Subject: [PATCH 04/17] add rust ffi to travis --- .travis.yml | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index c611de8..ab68df0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,22 +5,36 @@ compiler: - g++ os: - linux - - -before_install: - - sudo apt-get -qq update - - sudo apt-get install -y make automake autotools-dev cmake -script: - - mkdir -p build - - cd build - - cmake .. - - make - - ctest - - gcov -n -o . src/gqf.cpp > /dev/null; branches: only: - mqfDevelopmenet - master +cache: + directories: + - "$HOME/.cargo" + - "target" -after_success: - - bash <(curl -s https://codecov.io/bash) +jobs: + include: + - &test + stage: test + before_install: + - sudo apt-get -qq update + - sudo apt-get install -y make automake autotools-dev cmake + script: + - mkdir -p build + - cd build + - cmake .. + - make + - ctest + - gcov -n -o . src/gqf.cpp > /dev/null; + after_success: + - bash <(curl -s https://codecov.io/bash) + - <<: *test + name: Rust FFI bindings + language: rust + rust: stable + env: + - RUSTFLAGS="-Clink-arg=-fuse-ld=gold" + script: + - cargo test From 5417584ee2ba9674933b647e5e36ed39b652b14a Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Sun, 3 Nov 2019 17:29:49 -0800 Subject: [PATCH 05/17] start rust API, move raw FFI into another module --- src/lib.rs | 84 +++++++++--------------------------------------------- 1 file changed, 13 insertions(+), 71 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 98b4b6d..a1ce2ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,77 +1,19 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] +mod raw; -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +use std::ptr; -#[cfg(test)] -mod tests { - use super::*; - use std::ffi::CString; - use std::ptr; - - #[test] - fn simple_counting_test() { - //except first item is inserted 5 times to full test _insert1 - let mut qf: QF = QF { - mem: ptr::null_mut(), - metadata: ptr::null_mut(), - blocks: ptr::null_mut(), - }; - - let counter_size = 2; - let qbits = 5; - let num_hash_bits = qbits + 8; - let maximum_count = (1u64 << counter_size) - 1; - let mut count = 0; - let mut fixed_counter = 0; - - let s = CString::new("").unwrap(); - - //INFO("Counter size = "< Date: Sun, 3 Nov 2019 17:29:49 -0800 Subject: [PATCH 07/17] start rust API, move raw FFI into another module --- src/lib.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/raw.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/raw.rs diff --git a/src/lib.rs b/src/lib.rs index a1ce2ab..ff53b11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ mod raw; +use std::ffi::CString; use std::ptr; pub struct MQF { @@ -17,3 +18,77 @@ impl Default for MQF { } } } + +impl MQF { + pub fn new(counter_size: u64, qbits: u64) -> MQF { + let mut mqf = MQF::default(); + + let num_hash_bits = qbits + 8; + let maximum_count = (1u64 << counter_size) - 1; + + let s = CString::new("").unwrap(); + + unsafe { + raw::qf_init( + &mut mqf.inner, + 1u64 << qbits, // nslots + num_hash_bits, // key_bits + 0, // label_bits + counter_size, // fixed_counter_size + 0, // blocksLabelSize + true, // mem + s.as_ptr(), // path + 0, // seed (doesn't matter) + ); + }; + + mqf + } + + pub fn insert(&mut self, key: u64, count: u64) { + unsafe { raw::qf_insert(&mut self.inner, key, count, false, false) }; + } + + pub fn count_key(&self, key: u64) -> u64 { + unsafe { raw::qf_count_key(&self.inner, key) } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn simple_counting_test_api() { + //except first item is inserted 5 times to full test _insert1 + let counter_size = 2; + let qbits = 5; + let mut qf: MQF = MQF::new(counter_size, qbits); + + let mut count = 0; + let mut fixed_counter = 0; + + for i in 0..=10 { + qf.insert(100, 1); + count = qf.count_key(100); + dbg!((count, fixed_counter)); + assert_eq!(count, 1 + i); + } + + qf.insert(1500, 50); + + count = qf.count_key(1500); + dbg!((count, fixed_counter)); + assert_eq!(count, 50); + + qf.insert(1600, 60); + count = qf.count_key(1600); + dbg!((count, fixed_counter)); + assert_eq!(count, 60); + + qf.insert(2000, 4000); + count = qf.count_key(2000); + dbg!((count, fixed_counter)); + assert_eq!(count, 4000); + } +} diff --git a/src/raw.rs b/src/raw.rs new file mode 100644 index 0000000..e6b3013 --- /dev/null +++ b/src/raw.rs @@ -0,0 +1,77 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::CString; + use std::ptr; + + #[test] + fn simple_counting_test() { + //except first item is inserted 5 times to full test _insert1 + let mut qf: QF = QF { + mem: ptr::null_mut(), + metadata: ptr::null_mut(), + blocks: ptr::null_mut(), + }; + + let counter_size = 2; + let qbits = 5; + let num_hash_bits = qbits + 8; + let maximum_count = (1u64 << counter_size) - 1; + let mut count = 0; + let mut fixed_counter = 0; + + let s = CString::new("").unwrap(); + + //INFO("Counter size = "<mem, src->mem, sizeof(qfmem)); memcpy(dest->metadata, src->metadata, sizeof(qfmetadata)); diff --git a/src/lib.rs b/src/lib.rs index ff53b11..9758282 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,22 @@ impl Default for MQF { } } +impl Drop for MQF { + fn drop(&mut self) { + unsafe { raw::qf_destroy(&mut self.inner) }; + } +} + +impl Clone for MQF { + fn clone(&self) -> Self { + let mut new_qf = MQF::default(); + unsafe { + raw::qf_copy(&mut new_qf.inner, &self.inner); + }; + new_qf + } +} + impl MQF { pub fn new(counter_size: u64, qbits: u64) -> MQF { let mut mqf = MQF::default(); From 49a49eef8c6e93db14146d7b10d49561992512b8 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Mon, 4 Nov 2019 06:17:56 +0000 Subject: [PATCH 09/17] first pass at iteration --- build.rs | 5 +++++ src/lib.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/build.rs b/build.rs index 9491eb5..6cbb6f7 100644 --- a/build.rs +++ b/build.rs @@ -40,11 +40,16 @@ fn main() { .clang_arg("-std=c++11") .header("include/gqf.h") .whitelist_type("QF") + .whitelist_type("QFi") .whitelist_function("qf_init") .whitelist_function("qf_insert") .whitelist_function("qf_count_key") .whitelist_function("qf_destroy") .whitelist_function("qf_copy") + .whitelist_function("qf_iterator") + .whitelist_function("qfi_get") + .whitelist_function("qfi_next") + .whitelist_function("qfi_end") .blacklist_type("std::*") .generate() .expect("Unable to generate bindings"); diff --git a/src/lib.rs b/src/lib.rs index 9758282..d8413ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,47 @@ impl MQF { pub fn count_key(&self, key: u64) -> u64 { unsafe { raw::qf_count_key(&self.inner, key) } } + + pub fn iter(&mut self) -> MQFIter { + let mut cfi = raw::QFi { + qf: ptr::null_mut(), + run: 0, + current: 0, + cur_start_index: 0, + cur_length: 0, + num_clusters: 0, + c_info: ptr::null_mut(), + }; + + // TODO: treat false + let result = unsafe { raw::qf_iterator(&mut self.inner, &mut cfi, 0) }; + + MQFIter { inner: cfi } + } +} + +pub struct MQFIter { + inner: raw::QFi, +} + +impl Iterator for MQFIter { + type Item = (u64, u64, u64); + + fn next(&mut self) -> Option { + if unsafe { raw::qfi_end(&mut self.inner) } != 0 { + None + } else { + let mut key = 0; + let mut value = 0; + let mut count = 0; + + unsafe { + raw::qfi_get(&mut self.inner, &mut key, &mut value, &mut count); + raw::qfi_next(&mut self.inner) + }; + Some((key, value, count)) + } + } } #[cfg(test)] @@ -107,4 +148,25 @@ mod tests { dbg!((count, fixed_counter)); assert_eq!(count, 4000); } + + #[test] + fn big_count() { + let mut qf = MQF::new(4, 5); + qf.insert(100, 100000); + let mut count = qf.count_key(100); + assert_eq!(count, 100000); + } + + #[test] + fn iter_next() { + let mut qf = MQF::new(4, 5); + qf.insert(100, 100000); + qf.insert(101, 10000); + qf.insert(102, 1000); + qf.insert(103, 100); + + let vals: Vec<(u64, u64, u64)> = qf.iter().collect(); + dbg!(&vals); + assert_eq!(vals.len(), 4); + } } From bc49f2b101d672e8818a42775338309a4a7cc4d4 Mon Sep 17 00:00:00 2001 From: Mohamed Abuelanin Date: Mon, 4 Nov 2019 21:16:43 +0200 Subject: [PATCH 10/17] cmake options to suppress building binaries & tests --- CMakeLists.txt | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e8110..3b1a354 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,25 @@ cmake_minimum_required(VERSION 3.2) + +# Options for enabling/disabling MQF binaries and tests + +option(SUPRESS_BIN "Suppress building MQF binaries" OFF) +option(SUPRESS_TESTS "Suppress building MQF tests" OFF) + +if(SUPRESS_BIN) + add_definitions(-DSUPRESS_BIN=1) +else() + add_definitions(-DSUPRESS_BIN=0) +endif() +if(SUPRESS_TESTS) + add_definitions(-DSUPRESS_TESTS=1) +else() + add_definitions(-DSUPRESS_TESTS=0) +endif() + +# ------------------ END Of Options ------------------ + + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3") @@ -38,7 +58,15 @@ include_directories(${STXXL_INCLUDE_DIRS}) add_subdirectory(src) -add_subdirectory(bin) -enable_testing() -add_subdirectory(tests) + +if (NOT SUPRESS_BIN) + message("Building MQF binaries") + add_subdirectory(bin) +endif() + +if (NOT SUPRESS_BIN) + message("Building MQF tests") + enable_testing() + add_subdirectory(tests) +endif() \ No newline at end of file From 8a1db65d68ed39bbb72ea034df27aa015dc249df Mon Sep 17 00:00:00 2001 From: Mohamed Abuelanin Date: Mon, 4 Nov 2019 21:25:36 +0200 Subject: [PATCH 11/17] changing variable name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b1a354..96f9b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ if (NOT SUPRESS_BIN) add_subdirectory(bin) endif() -if (NOT SUPRESS_BIN) +if (NOT DSUPRESS_TESTS) message("Building MQF tests") enable_testing() add_subdirectory(tests) From 8053c8d381961aae42c4c6b1ab7fd68bfc6f2442 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Mon, 4 Nov 2019 21:35:41 +0000 Subject: [PATCH 12/17] serialization --- Cargo.toml | 3 ++- build.rs | 2 ++ src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3d3f675..35d667a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ links = "libmqf" bindgen = "0.51" cmake = "0.1.42" -[dependencies] +[dev-dependencies] +tempfile = "3.1.0" diff --git a/build.rs b/build.rs index 6cbb6f7..103a09a 100644 --- a/build.rs +++ b/build.rs @@ -46,6 +46,8 @@ fn main() { .whitelist_function("qf_count_key") .whitelist_function("qf_destroy") .whitelist_function("qf_copy") + .whitelist_function("qf_serialize") + .whitelist_function("qf_deserialize") .whitelist_function("qf_iterator") .whitelist_function("qfi_get") .whitelist_function("qfi_next") diff --git a/src/lib.rs b/src/lib.rs index d8413ba..ecddba2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ mod raw; use std::ffi::CString; +use std::path::Path; use std::ptr; pub struct MQF { @@ -85,6 +86,27 @@ impl MQF { MQFIter { inner: cfi } } + + pub fn serialize>(&self, path: P) -> Result<(), Box> { + let s = CString::new(path.as_ref().to_str().unwrap())?; + + unsafe { + raw::qf_serialize(&self.inner, s.as_ptr()); + } + + Ok(()) + } + + pub fn deserialize>(path: P) -> Result> { + let mut qf = MQF::default(); + let s = CString::new(path.as_ref().to_str().unwrap())?; + + unsafe { + raw::qf_deserialize(&mut qf.inner, s.as_ptr()); + } + + Ok(qf) + } } pub struct MQFIter { @@ -169,4 +191,22 @@ mod tests { dbg!(&vals); assert_eq!(vals.len(), 4); } + + #[test] + fn serde() { + let mut qf = MQF::new(4, 5); + qf.insert(100, 100000); + qf.insert(101, 10000); + qf.insert(102, 1000); + qf.insert(103, 100); + + let vals: Vec<(u64, u64, u64)> = qf.iter().collect(); + + let mut file = tempfile::NamedTempFile::new().unwrap(); + qf.serialize(file.path()).unwrap(); + + let mut new_qf = MQF::deserialize(file.path()).unwrap(); + let new_vals: Vec<(u64, u64, u64)> = new_qf.iter().collect(); + assert_eq!(vals, new_vals); + } } From ab2e7efac3bccb86910806dfce3864480b5b6e23 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Mon, 4 Nov 2019 21:41:38 +0000 Subject: [PATCH 13/17] avoid building binaries and tests --- build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 103a09a..b044c9b 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,11 @@ extern crate cmake; use cmake::Config; fn main() { - let dst = Config::new(".").define("BUILD_STATIC_LIBS", "ON").build(); + let dst = Config::new(".") + .define("BUILD_STATIC_LIBS", "ON") + .define("SUPRESS_BIN", "ON") + .define("SUPRESS_TESTS", "ON") + .build(); // TODO: there are probably better ways to do this... let target = env::var("TARGET").unwrap(); From d6f0e5b735c9e1914efe8301b881db0688ef8e4d Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Wed, 6 Nov 2019 23:37:44 +0000 Subject: [PATCH 14/17] add merge and remove stxxl from build.rs --- build.rs | 14 +------------- src/lib.rs | 13 +++++++++++-- src/raw.rs | 4 ++++ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index b044c9b..5ecf79d 100644 --- a/build.rs +++ b/build.rs @@ -22,20 +22,7 @@ fn main() { } println!("cargo:rustc-link-search=native={}/build/src", dst.display()); - println!( - "cargo:rustc-link-search=native={}/build/ThirdParty/stxxl/lib", - dst.display() - ); - // TODO: static libs are being generated in lib too, - // cmake seems to be just copying it from the right locations. - // But not sure we should be using them... - // println!("cargo:rustc-link-search=native=lib"); - println!("cargo:rustc-link-lib=static=MQF"); - // TODO: there are two names for stxxl, depending on being built on release - // or debug mode... - //println!("cargo:rustc-link-lib=static=stxxl"); - println!("cargo:rustc-link-lib=static=stxxl_debug"); let bindings = bindgen::Builder::default() .clang_arg("-I./include") @@ -52,6 +39,7 @@ fn main() { .whitelist_function("qf_copy") .whitelist_function("qf_serialize") .whitelist_function("qf_deserialize") + .whitelist_function("qf_migrate") .whitelist_function("qf_iterator") .whitelist_function("qfi_get") .whitelist_function("qfi_next") diff --git a/src/lib.rs b/src/lib.rs index ecddba2..f0b89a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ use std::ffi::CString; use std::path::Path; use std::ptr; +#[derive(Debug)] pub struct MQF { inner: raw::QF, } @@ -55,7 +56,7 @@ impl MQF { 0, // blocksLabelSize true, // mem s.as_ptr(), // path - 0, // seed (doesn't matter) + 2038074760, // seed (doesn't matter) ); }; @@ -82,7 +83,7 @@ impl MQF { }; // TODO: treat false - let result = unsafe { raw::qf_iterator(&mut self.inner, &mut cfi, 0) }; + let _ = unsafe { raw::qf_iterator(&mut self.inner, &mut cfi, 0) }; MQFIter { inner: cfi } } @@ -107,6 +108,14 @@ impl MQF { Ok(qf) } + + pub fn merge(&mut self, other: &mut MQF) -> Result<(), Box> { + unsafe { + raw::qf_migrate(&mut other.inner, &mut self.inner); + } + + Ok(()) + } } pub struct MQFIter { diff --git a/src/raw.rs b/src/raw.rs index e6b3013..b199b4a 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -2,8 +2,12 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(dead_code)] +#![allow(improper_ctypes)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +// TODO: eventually want to remove the `improper_ctypes` lint, +// but MQF is using uint128_t internally... + #[cfg(test)] mod tests { use super::*; From b557436bf68d128f2962f23b7a5ad07f16b26493 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Wed, 6 Nov 2019 23:44:04 +0000 Subject: [PATCH 15/17] implement Sync, but need more testing --- src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f0b89a5..f6f1599 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,12 +37,13 @@ impl Clone for MQF { } } +unsafe impl Sync for MQF {} + impl MQF { pub fn new(counter_size: u64, qbits: u64) -> MQF { let mut mqf = MQF::default(); let num_hash_bits = qbits + 8; - let maximum_count = (1u64 << counter_size) - 1; let s = CString::new("").unwrap(); @@ -64,7 +65,8 @@ impl MQF { } pub fn insert(&mut self, key: u64, count: u64) { - unsafe { raw::qf_insert(&mut self.inner, key, count, false, false) }; + unsafe { raw::qf_insert(&mut self.inner, key, count, true, true) }; + //unsafe { raw::qf_insert(&mut self.inner, key, count, false, false) }; } pub fn count_key(&self, key: u64) -> u64 { From c46955905aa3065548b3c2c87c798f825c674ab4 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Thu, 7 Nov 2019 03:01:55 +0000 Subject: [PATCH 16/17] bring linking to stxxl back --- build.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build.rs b/build.rs index 5ecf79d..42d796d 100644 --- a/build.rs +++ b/build.rs @@ -24,6 +24,17 @@ fn main() { println!("cargo:rustc-link-search=native={}/build/src", dst.display()); println!("cargo:rustc-link-lib=static=MQF"); + println!( + "cargo:rustc-link-search=native={}/build/ThirdParty/stxxl/lib", + dst.display() + ); + + let mode = match env::var("PROFILE").unwrap().as_ref() { + "debug" => "_debug", + _ => "", + }; + println!("cargo:rustc-link-lib=static=stxxl{}", mode); + let bindings = bindgen::Builder::default() .clang_arg("-I./include") .clang_arg("-x") From dee6e9d862d6d82d40bd5f15019f5397a1d20b9f Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Thu, 7 Nov 2019 05:55:20 +0000 Subject: [PATCH 17/17] revert cmake changes --- CMakeLists.txt | 34 +++------------------------------- build.rs | 3 +-- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96f9b2b..d9e8110 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,25 +1,5 @@ cmake_minimum_required(VERSION 3.2) - -# Options for enabling/disabling MQF binaries and tests - -option(SUPRESS_BIN "Suppress building MQF binaries" OFF) -option(SUPRESS_TESTS "Suppress building MQF tests" OFF) - -if(SUPRESS_BIN) - add_definitions(-DSUPRESS_BIN=1) -else() - add_definitions(-DSUPRESS_BIN=0) -endif() -if(SUPRESS_TESTS) - add_definitions(-DSUPRESS_TESTS=1) -else() - add_definitions(-DSUPRESS_TESTS=0) -endif() - -# ------------------ END Of Options ------------------ - - set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3") @@ -58,15 +38,7 @@ include_directories(${STXXL_INCLUDE_DIRS}) add_subdirectory(src) +add_subdirectory(bin) - -if (NOT SUPRESS_BIN) - message("Building MQF binaries") - add_subdirectory(bin) -endif() - -if (NOT DSUPRESS_TESTS) - message("Building MQF tests") - enable_testing() - add_subdirectory(tests) -endif() \ No newline at end of file +enable_testing() +add_subdirectory(tests) diff --git a/build.rs b/build.rs index 42d796d..bc895ac 100644 --- a/build.rs +++ b/build.rs @@ -7,8 +7,7 @@ use cmake::Config; fn main() { let dst = Config::new(".") .define("BUILD_STATIC_LIBS", "ON") - .define("SUPRESS_BIN", "ON") - .define("SUPRESS_TESTS", "ON") + .build_target("MQF") .build(); // TODO: there are probably better ways to do this...