mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 18:08:56 -06:00
Merge pull request #2 from mbillingr/cmake-mrg
add optional cmake builds
This commit is contained in:
@@ -4,7 +4,12 @@ jobs:
|
|||||||
docker:
|
docker:
|
||||||
- image: rustlang/rust:nightly
|
- image: rustlang/rust:nightly
|
||||||
steps:
|
steps:
|
||||||
|
- run: apt -y update --fix-missing
|
||||||
|
- run: apt -y install cmake
|
||||||
- checkout
|
- checkout
|
||||||
- run: git submodule update --init --recursive
|
- run: git submodule update --init --recursive
|
||||||
- run: cargo build
|
- run: cargo build
|
||||||
- run: cd examples && ./test.sh
|
- run: cd examples && ./test.sh
|
||||||
|
- run: |
|
||||||
|
git clean -dfx
|
||||||
|
cargo build --no-default-features --features cmake
|
||||||
|
|||||||
@@ -8,8 +8,12 @@ edition = "2018"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["autotools"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
autotools = "0.2"
|
autotools = { version = "0.2", optional = true }
|
||||||
|
cmake = { version = "0.1", optional = true }
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ This crate is for use cases in which developers need to integrate [`bdwgc`][bdwg
|
|||||||
|
|
||||||
See [`examples`](examples) directory.
|
See [`examples`](examples) directory.
|
||||||
|
|
||||||
|
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo build --no-default-features --features cmake
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](LICENSE)
|
[MIT](LICENSE)
|
||||||
|
|||||||
27
build.rs
27
build.rs
@@ -1,6 +1,7 @@
|
|||||||
const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops";
|
const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops";
|
||||||
const LIB_GC_DIR: &str = "vendor/bdwgc";
|
const LIB_GC_DIR: &str = "vendor/bdwgc";
|
||||||
|
|
||||||
|
#[cfg(feature = "autotools")]
|
||||||
fn main() {
|
fn main() {
|
||||||
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
||||||
std::process::Command::new("sh")
|
std::process::Command::new("sh")
|
||||||
@@ -41,3 +42,29 @@ fn main() {
|
|||||||
.unwrap();
|
.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");
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"coroutines",
|
|
||||||
"dynamic_threads",
|
"dynamic_threads",
|
||||||
"free_by_borrow",
|
"free_by_borrow",
|
||||||
"free_by_gc",
|
"free_by_gc",
|
||||||
"static_threads",
|
"static_threads",
|
||||||
"suspended_coroutines",
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "coroutines"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bdwgc-alloc = { path = "../.." }
|
|
||||||
coroutine = "0.8"
|
|
||||||
@@ -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 {}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "suspended_coroutines"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bdwgc-alloc = { path = "../.." }
|
|
||||||
coroutine = "0.8"
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: 2b7003769e...ddd788fc3c
2
vendor/libatomic_ops
vendored
2
vendor/libatomic_ops
vendored
Submodule vendor/libatomic_ops updated: 6287479564...ae996e93f0
Reference in New Issue
Block a user