From daa9d4c2093dd48a29c1c3ab7280111b67dfee68 Mon Sep 17 00:00:00 2001 From: mbilling Date: Wed, 11 Sep 2019 15:19:52 +0200 Subject: [PATCH 1/5] add optional cmake builds --- Cargo.toml | 6 +++++- README.md | 7 +++++++ build.rs | 27 +++++++++++++++++++++++++++ vendor/bdwgc | 2 +- vendor/libatomic_ops | 2 +- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9468707..7a9237d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,12 @@ edition = "2018" license = "MIT" build = "build.rs" +[features] +default = ["autotools"] + [dependencies] libc = "0.2" [build-dependencies] -autotools = "0.2" +autotools = {version = "0.2", optional = true} +cmake = {version = "0.1", optional = true} diff --git a/README.md b/README.md index 967e656..5e1ee26 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ This crate is for use cases in which developers need to integrate [`bdwgc`][bdwg See [`examples`](examples) directory. +By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake enable the `cmake` feature in `Cargo.toml`: + + [dependencies.bdwgc-alloc] + version = "0.4" + default-features = false + features = ["cmake"] + ## License [MIT](LICENSE) diff --git a/build.rs b/build.rs index a475b65..2cbf54e 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,7 @@ const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops"; const LIB_GC_DIR: &str = "vendor/bdwgc"; +#[cfg(feature = "autotools")] fn main() { for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] { std::process::Command::new("sh") @@ -41,3 +42,29 @@ fn main() { .unwrap(); } } + +#[cfg(feature = "cmake")] +fn main() { + use cmake::Config; + use std::path::Path; + + let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR) + .join("src") + .canonicalize() + .unwrap() + .display() + .to_string() + .replace(r"\\?\", ""); + + let dst = Config::new(LIB_GC_DIR) + .profile("Release") + .define("BUILD_SHARED_LIBS", "FALSE") + .cflag(format!("-I{}", libatomic_include_path)) + .build(); + + println!( + "cargo:rustc-link-search=native={}", + dst.join("lib").display() + ); + println!("cargo:rustc-link-lib=static=gc"); +} diff --git a/vendor/bdwgc b/vendor/bdwgc index 2b70037..a20818b 160000 --- a/vendor/bdwgc +++ b/vendor/bdwgc @@ -1 +1 @@ -Subproject commit 2b7003769e1ecc941ef80b603cba16a121f37997 +Subproject commit a20818be9ec660588af325d82e515ebb75bd9905 diff --git a/vendor/libatomic_ops b/vendor/libatomic_ops index 6287479..ae996e9 160000 --- a/vendor/libatomic_ops +++ b/vendor/libatomic_ops @@ -1 +1 @@ -Subproject commit 6287479564021893f2bf81149d0738bcb492b81c +Subproject commit ae996e93f0ddfb8e2a93d49c6d7edc1478ad60c1 From 38958d31384ad13cabf918c2a026f11dc77532c0 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Mon, 30 Sep 2019 21:53:45 -0700 Subject: [PATCH 2/5] Test build on CI --- .circleci/config.yml | 3 +++ Cargo.toml | 4 ++-- README.md | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3772749..79f9eb0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,3 +8,6 @@ jobs: - run: git submodule update --init --recursive - run: cargo build - run: cd examples && ./test.sh + - run: | + git clean -dfx + cargo build --no-default-features --features cmake diff --git a/Cargo.toml b/Cargo.toml index 7a9237d..4f69945 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,5 @@ default = ["autotools"] libc = "0.2" [build-dependencies] -autotools = {version = "0.2", optional = true} -cmake = {version = "0.1", optional = true} +autotools = { version = "0.2", optional = true } +cmake = { version = "0.1", optional = true } diff --git a/README.md b/README.md index 5e1ee26..f3807e8 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,11 @@ This crate is for use cases in which developers need to integrate [`bdwgc`][bdwg See [`examples`](examples) directory. -By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake enable the `cmake` feature in `Cargo.toml`: +By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature: - [dependencies.bdwgc-alloc] - version = "0.4" - default-features = false - features = ["cmake"] +```sh +cargo build --no-default-features --features cmake +``` ## License From 468dedbadd53977323ef9284b3362f99381a6b9c Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Mon, 30 Sep 2019 21:57:45 -0700 Subject: [PATCH 3/5] Update bdwgc repository --- vendor/bdwgc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/bdwgc b/vendor/bdwgc index a20818b..ddd788f 160000 --- a/vendor/bdwgc +++ b/vendor/bdwgc @@ -1 +1 @@ -Subproject commit a20818be9ec660588af325d82e515ebb75bd9905 +Subproject commit ddd788fc3c3701405efde47c3f540bdf01c878dd From 052a8962928fb9d375539cb492fbef3ff66be1c8 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Mon, 30 Sep 2019 22:08:13 -0700 Subject: [PATCH 4/5] Remove coroutine examples --- examples/Cargo.toml | 2 -- examples/coroutines/Cargo.toml | 10 ------- examples/coroutines/src/main.rs | 26 ------------------ examples/suspended_coroutines/Cargo.toml | 10 ------- examples/suspended_coroutines/src/main.rs | 33 ----------------------- 5 files changed, 81 deletions(-) delete mode 100644 examples/coroutines/Cargo.toml delete mode 100644 examples/coroutines/src/main.rs delete mode 100644 examples/suspended_coroutines/Cargo.toml delete mode 100644 examples/suspended_coroutines/src/main.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index be26faa..5cb5511 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,9 +1,7 @@ [workspace] members = [ - "coroutines", "dynamic_threads", "free_by_borrow", "free_by_gc", "static_threads", - "suspended_coroutines", ] diff --git a/examples/coroutines/Cargo.toml b/examples/coroutines/Cargo.toml deleted file mode 100644 index b1e9856..0000000 --- a/examples/coroutines/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "coroutines" -version = "0.1.0" -authors = ["Yota Toyama "] -edition = "2018" -publish = false - -[dependencies] -bdwgc-alloc = { path = "../.." } -coroutine = "0.8" diff --git a/examples/coroutines/src/main.rs b/examples/coroutines/src/main.rs deleted file mode 100644 index 41ae7d8..0000000 --- a/examples/coroutines/src/main.rs +++ /dev/null @@ -1,26 +0,0 @@ -extern crate bdwgc_alloc; -extern crate coroutine; - -use bdwgc_alloc::Allocator; -use coroutine::asymmetric::Coroutine; -use std::alloc::Layout; - -#[global_allocator] -static GLOBAL_ALLOCATOR: Allocator = Allocator; - -fn main() { - unsafe { Allocator::initialize() } - Allocator::lock(); - - let handle = Coroutine::spawn(move |_, _| { - let bottom: u8 = 0; - unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::unlock(); - - loop { - unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; - } - }); - - for _ in handle {} -} diff --git a/examples/suspended_coroutines/Cargo.toml b/examples/suspended_coroutines/Cargo.toml deleted file mode 100644 index 931ba11..0000000 --- a/examples/suspended_coroutines/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "suspended_coroutines" -version = "0.1.0" -authors = ["Yota Toyama "] -edition = "2018" -publish = false - -[dependencies] -bdwgc-alloc = { path = "../.." } -coroutine = "0.8" diff --git a/examples/suspended_coroutines/src/main.rs b/examples/suspended_coroutines/src/main.rs deleted file mode 100644 index 87d44f5..0000000 --- a/examples/suspended_coroutines/src/main.rs +++ /dev/null @@ -1,33 +0,0 @@ -extern crate bdwgc_alloc; -extern crate coroutine; - -use bdwgc_alloc::Allocator; -use coroutine::asymmetric::Coroutine; -use std::alloc::Layout; - -#[global_allocator] -static GLOBAL_ALLOCATOR: Allocator = Allocator; - -fn main() { - unsafe { Allocator::initialize() } - - Allocator::lock(); - let mut handle = Coroutine::spawn(move |me, _| { - let bottom: u8 = 0; - unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::unlock(); - - me.yield_with(42); - unsafe { Allocator::set_stack_bottom(&bottom) } - Allocator::unlock(); - - loop { - unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) }; - } - }); - - Allocator::lock(); - assert_eq!(handle.resume(0).unwrap(), 42); - - handle.resume(0).unwrap(); -} From 1187fcbb87ed42d3d42f1bfb538cecf87849d3e2 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Mon, 30 Sep 2019 22:17:25 -0700 Subject: [PATCH 5/5] Install cmake --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79f9eb0..6d9a366 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,6 +4,8 @@ jobs: docker: - image: rustlang/rust:nightly steps: + - run: apt -y update --fix-missing + - run: apt -y install cmake - checkout - run: git submodule update --init --recursive - run: cargo build