mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-09-26 12:13:39 -06:00
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
- run: cargo fmt -- --check
|
- run: cargo fmt --all -- --check
|
||||||
spell-check:
|
spell-check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[submodule "vendor/bdwgc"]
|
[submodule "vendor/bdwgc"]
|
||||||
path = vendor/bdwgc
|
path = bdwgc-alloc-sys/vendor/bdwgc
|
||||||
url = https://github.com/bdwgc/bdwgc
|
url = https://github.com/bdwgc/bdwgc
|
||||||
[submodule "vendor/libatomic_ops"]
|
[submodule "vendor/libatomic_ops"]
|
||||||
path = vendor/libatomic_ops
|
path = bdwgc-alloc-sys/vendor/libatomic_ops
|
||||||
url = https://github.com/bdwgc/libatomic_ops
|
url = https://github.com/bdwgc/libatomic_ops
|
||||||
|
|||||||
Generated
+207
-4
@@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autotools"
|
name = "autotools"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
@@ -15,11 +24,43 @@ dependencies = [
|
|||||||
name = "bdwgc-alloc"
|
name = "bdwgc-alloc"
|
||||||
version = "0.6.15"
|
version = "0.6.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autotools",
|
"bdwgc-alloc-sys",
|
||||||
"cmake",
|
|
||||||
"libc",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bdwgc-alloc-sys"
|
||||||
|
version = "0.6.15"
|
||||||
|
dependencies = [
|
||||||
|
"autotools",
|
||||||
|
"bindgen",
|
||||||
|
"cmake",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bindgen"
|
||||||
|
version = "0.73.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cexpr",
|
||||||
|
"clang-sys",
|
||||||
|
"log",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"rustc-hash",
|
||||||
|
"shlex 2.0.1",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.13.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.49"
|
version = "1.2.49"
|
||||||
@@ -27,7 +68,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215"
|
checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"shlex",
|
"shlex 1.3.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cexpr"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clang-sys"
|
||||||
|
version = "1.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
|
||||||
|
dependencies = [
|
||||||
|
"glob",
|
||||||
|
"libc",
|
||||||
|
"libloading",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -66,21 +133,157 @@ dependencies = [
|
|||||||
"bdwgc-alloc",
|
"bdwgc-alloc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.189"
|
version = "0.2.189"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.8.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"windows-link",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.107"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.47"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "2.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_threads"
|
name = "static_threads"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bdwgc-alloc",
|
"bdwgc-alloc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "3.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|||||||
+9
-22
@@ -1,34 +1,21 @@
|
|||||||
[package]
|
|
||||||
name = "bdwgc-alloc"
|
|
||||||
version = "0.6.15"
|
|
||||||
edition = "2024"
|
|
||||||
description = "impl GlobalAlloc for bdwgc"
|
|
||||||
documentation = "https://bdwgc.github.io/bdwgc-rust/bdwgc_alloc/"
|
|
||||||
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
|
||||||
license = "MIT"
|
|
||||||
categories = ["api-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = ["examples/*"]
|
members = ["bdwgc-alloc", "bdwgc-alloc-sys", "examples/*"]
|
||||||
|
default-members = ["bdwgc-alloc", "bdwgc-alloc-sys"]
|
||||||
|
|
||||||
[dependencies]
|
[workspace.package]
|
||||||
libc = "0.2.186"
|
version = "0.6.15"
|
||||||
|
edition = "2024"
|
||||||
|
repository = "https://github.com/bdwgc/bdwgc-rust"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
[build-dependencies]
|
[workspace.lints.clippy]
|
||||||
autotools = { version = "0.2.7", optional = true }
|
|
||||||
cmake = { version = "0.1.58", optional = true }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["autotools"]
|
|
||||||
|
|
||||||
[lints.clippy]
|
|
||||||
alloc_instead_of_core = "deny"
|
alloc_instead_of_core = "deny"
|
||||||
dbg_macro = "deny"
|
dbg_macro = "deny"
|
||||||
missing_const_for_fn = "deny"
|
missing_const_for_fn = "deny"
|
||||||
std_instead_of_alloc = "deny"
|
std_instead_of_alloc = "deny"
|
||||||
std_instead_of_core = "deny"
|
std_instead_of_core = "deny"
|
||||||
|
|
||||||
[lints.rust]
|
[workspace.lints.rust]
|
||||||
missing_docs = "deny"
|
missing_docs = "deny"
|
||||||
warnings = "deny"
|
warnings = "deny"
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
This crate is for use cases in which developers need to integrate [`bdwgc`][bdwgc] into their programs written in Rust (e.g. writing a runtime library in Rust for their own programming language whose GC is done by [`bdwgc`][bdwgc].)
|
This crate is for use cases in which developers need to integrate [`bdwgc`][bdwgc] into their programs written in Rust (e.g. writing a runtime library in Rust for their own programming language whose GC is done by [`bdwgc`][bdwgc].)
|
||||||
|
|
||||||
|
The raw bindings to the C API of [`bdwgc`][bdwgc] that this crate is built on are available as the `bdwgc-alloc-sys` crate.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
See [`examples`](https://github.com/bdwgc/bdwgc-rust/tree/main/examples) directory.
|
See [`examples`](https://github.com/bdwgc/bdwgc-rust/tree/main/examples) directory.
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
[package]
|
||||||
|
name = "bdwgc-alloc-sys"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
description = "Rust bindings to the bdwgc C API"
|
||||||
|
documentation = "https://bdwgc.github.io/bdwgc-rust/bdwgc_alloc_sys/"
|
||||||
|
repository.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
categories = ["external-ffi-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
||||||
|
links = "gc"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
autotools = { version = "0.2.7", optional = true }
|
||||||
|
bindgen = "0.73.2"
|
||||||
|
cmake = { version = "0.1.58", optional = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["autotools"]
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "collector"
|
||||||
|
harness = false
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# bdwgc-alloc-sys
|
||||||
|
|
||||||
|
[](https://github.com/bdwgc/bdwgc-rust/actions)
|
||||||
|
[](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
||||||
|
|
||||||
|
Rust bindings to the C API of [`bdwgc`][bdwgc], the conservative garbage collector.
|
||||||
|
|
||||||
|
This crate builds [`bdwgc`][bdwgc] from its vendored source and links it statically. The bindings are generated from its headers at build time by [`bindgen`](https://github.com/rust-lang/rust-bindgen), which requires `libclang`.
|
||||||
|
|
||||||
|
See the [`bdwgc-alloc`](https://crates.io/crates/bdwgc-alloc) crate for a [`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation on top of these bindings.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo add bdwgc-alloc-sys
|
||||||
|
```
|
||||||
|
|
||||||
|
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo add bdwgc-alloc-sys --no-default-features --features cmake
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[MIT](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
||||||
|
|
||||||
|
[bdwgc]: https://github.com/bdwgc/bdwgc
|
||||||
@@ -1,18 +1,36 @@
|
|||||||
//! A build script.
|
//! A build script.
|
||||||
|
|
||||||
|
use core::error::Error;
|
||||||
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
build_library()?;
|
||||||
|
|
||||||
|
bindgen::builder()
|
||||||
|
.header(format!("{LIB_GC_DIR}/include/gc.h"))
|
||||||
|
.clang_arg(format!("-I{LIB_GC_DIR}/include"))
|
||||||
|
.clang_arg("-DGC_THREADS")
|
||||||
|
.use_core()
|
||||||
|
.allowlist_item("GC_.*")
|
||||||
|
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
|
||||||
|
.generate()?
|
||||||
|
.write_to_file(PathBuf::from(env::var("OUT_DIR")?).join("bindings.rs"))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
cfg_select! {
|
cfg_select! {
|
||||||
feature = "cmake" => {
|
feature = "cmake" => {
|
||||||
fn main() {
|
fn build_library() -> Result<(), Box<dyn Error>> {
|
||||||
use cmake::Config;
|
use cmake::Config;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR)
|
let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR)
|
||||||
.join("src")
|
.join("src")
|
||||||
.canonicalize()
|
.canonicalize()?
|
||||||
.unwrap()
|
|
||||||
.display()
|
.display()
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace(r"\\?\", "");
|
.replace(r"\\?\", "");
|
||||||
@@ -28,16 +46,17 @@ cfg_select! {
|
|||||||
dst.join("lib").display()
|
dst.join("lib").display()
|
||||||
);
|
);
|
||||||
println!("cargo:rustc-link-lib=static=gc");
|
println!("cargo:rustc-link-lib=static=gc");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feature = "autotools" => {
|
feature = "autotools" => {
|
||||||
fn main() {
|
fn build_library() -> Result<(), Box<dyn Error>> {
|
||||||
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")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(format!("cd {dir} && ./autogen.sh"))
|
.arg(format!("cd {dir} && ./autogen.sh"))
|
||||||
.output()
|
.output()?;
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR)
|
let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR)
|
||||||
@@ -68,9 +87,10 @@ cfg_select! {
|
|||||||
std::process::Command::new("sh")
|
std::process::Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(format!("cd {dir} && git clean -dfx"))
|
.arg(format!("cd {dir} && git clean -dfx"))
|
||||||
.output()
|
.output()?;
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#![doc = include_str!("../README.md")]
|
||||||
|
#![no_std]
|
||||||
|
#![allow(missing_docs)]
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
#![allow(non_upper_case_globals)]
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
//! A smoke test of the bindings.
|
||||||
|
|
||||||
|
use bdwgc_alloc_sys::{
|
||||||
|
GC_SUCCESS, GC_allow_register_threads, GC_free, GC_gcollect, GC_get_stack_base, GC_init,
|
||||||
|
GC_malloc, GC_realloc, GC_register_finalizer, GC_register_my_thread, GC_stack_base,
|
||||||
|
GC_unregister_my_thread,
|
||||||
|
};
|
||||||
|
use core::{
|
||||||
|
ffi::c_void,
|
||||||
|
ptr::null_mut,
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
};
|
||||||
|
use std::thread::spawn;
|
||||||
|
|
||||||
|
const TOTAL_COUNT: usize = 1 << 10;
|
||||||
|
|
||||||
|
static FINALIZED_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
unsafe {
|
||||||
|
GC_init();
|
||||||
|
GC_allow_register_threads();
|
||||||
|
}
|
||||||
|
|
||||||
|
allocate();
|
||||||
|
finalize();
|
||||||
|
register_thread();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allocate() {
|
||||||
|
let ptr = unsafe { GC_malloc(42) };
|
||||||
|
assert!(!ptr.is_null());
|
||||||
|
|
||||||
|
let ptr = unsafe { GC_realloc(ptr, 84) };
|
||||||
|
assert!(!ptr.is_null());
|
||||||
|
|
||||||
|
unsafe { GC_free(ptr) };
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finalize() {
|
||||||
|
extern "C" fn count(_object: *mut c_void, _client_data: *mut c_void) {
|
||||||
|
FINALIZED_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
for _ in 0..TOTAL_COUNT {
|
||||||
|
unsafe {
|
||||||
|
GC_register_finalizer(
|
||||||
|
GC_malloc(42),
|
||||||
|
Some(count),
|
||||||
|
null_mut(),
|
||||||
|
null_mut(),
|
||||||
|
null_mut(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe { GC_gcollect() };
|
||||||
|
|
||||||
|
// TODO Is there any way to collect all?
|
||||||
|
assert!(FINALIZED_COUNT.load(Ordering::Relaxed) > TOTAL_COUNT / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_thread() {
|
||||||
|
spawn(|| {
|
||||||
|
let mut base = GC_stack_base {
|
||||||
|
mem_base: null_mut(),
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(unsafe { GC_get_stack_base(&mut base) }, GC_SUCCESS);
|
||||||
|
assert_eq!(unsafe { GC_register_my_thread(&base) }, GC_SUCCESS);
|
||||||
|
assert!(!unsafe { GC_malloc(42) }.is_null());
|
||||||
|
assert_eq!(unsafe { GC_unregister_my_thread() }, GC_SUCCESS);
|
||||||
|
})
|
||||||
|
.join()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "bdwgc-alloc"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
description = "impl GlobalAlloc for bdwgc"
|
||||||
|
documentation = "https://bdwgc.github.io/bdwgc-rust/bdwgc_alloc/"
|
||||||
|
repository.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
categories = ["api-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bdwgc-alloc-sys = { version = "0.6.15", path = "../bdwgc-alloc-sys", default-features = false }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["autotools"]
|
||||||
|
autotools = ["bdwgc-alloc-sys/autotools"]
|
||||||
|
cmake = ["bdwgc-alloc-sys/cmake"]
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../README.md
|
||||||
@@ -3,42 +3,16 @@
|
|||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
|
use bdwgc_alloc_sys::{
|
||||||
|
GC_SUCCESS, GC_alloc_lock, GC_alloc_unlock, GC_allow_register_threads, GC_free, GC_gcollect,
|
||||||
|
GC_get_stack_base, GC_init, GC_malloc, GC_realloc, GC_register_finalizer,
|
||||||
|
GC_register_my_thread, GC_set_stackbottom, GC_stack_base, GC_unregister_my_thread,
|
||||||
|
};
|
||||||
use core::{
|
use core::{
|
||||||
alloc::{GlobalAlloc, Layout},
|
alloc::{GlobalAlloc, Layout},
|
||||||
ptr::null,
|
ffi::c_void,
|
||||||
|
ptr::null_mut,
|
||||||
};
|
};
|
||||||
use libc::{c_int, c_void, size_t};
|
|
||||||
|
|
||||||
const GC_SUCCESS: c_int = 0;
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
struct GcStackBase {
|
|
||||||
mem_base: *const c_void,
|
|
||||||
// TODO: Add reg_base field to support IA64.
|
|
||||||
}
|
|
||||||
|
|
||||||
#[link(name = "gc", kind = "static")]
|
|
||||||
unsafe extern "C" {
|
|
||||||
fn GC_allow_register_threads();
|
|
||||||
fn GC_alloc_lock();
|
|
||||||
fn GC_alloc_unlock();
|
|
||||||
fn GC_free(ptr: *mut c_void);
|
|
||||||
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
|
|
||||||
fn GC_init();
|
|
||||||
fn GC_malloc(size: size_t) -> *mut c_void;
|
|
||||||
fn GC_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
|
|
||||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
|
||||||
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
|
||||||
fn GC_unregister_my_thread();
|
|
||||||
fn GC_gcollect();
|
|
||||||
fn GC_register_finalizer(
|
|
||||||
ptr: *const c_void,
|
|
||||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
|
||||||
client_data: *const c_void,
|
|
||||||
opt_old_finalizer: *const c_void,
|
|
||||||
opt_old_client_data: *const c_void,
|
|
||||||
) -> *mut c_void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An allocator.
|
/// An allocator.
|
||||||
pub struct Allocator;
|
pub struct Allocator;
|
||||||
@@ -72,7 +46,9 @@ impl Allocator {
|
|||||||
///
|
///
|
||||||
/// This function must not be called in a main thread.
|
/// This function must not be called in a main thread.
|
||||||
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
||||||
let mut base = GcStackBase { mem_base: null() };
|
let mut base = GC_stack_base {
|
||||||
|
mem_base: null_mut(),
|
||||||
|
};
|
||||||
|
|
||||||
if unsafe { GC_get_stack_base(&mut base) } != GC_SUCCESS {
|
if unsafe { GC_get_stack_base(&mut base) } != GC_SUCCESS {
|
||||||
return Err(error::Error::new("failed to get stack base"));
|
return Err(error::Error::new("failed to get stack base"));
|
||||||
@@ -94,9 +70,9 @@ impl Allocator {
|
|||||||
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
||||||
unsafe {
|
unsafe {
|
||||||
GC_set_stackbottom(
|
GC_set_stackbottom(
|
||||||
null(),
|
null_mut(),
|
||||||
&GcStackBase {
|
&GC_stack_base {
|
||||||
mem_base: bottom as *const libc::c_void,
|
mem_base: bottom.cast_mut().cast(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -108,7 +84,7 @@ impl Allocator {
|
|||||||
///
|
///
|
||||||
/// The thread must be registered already.
|
/// The thread must be registered already.
|
||||||
pub unsafe fn unregister_current_thread() {
|
pub unsafe fn unregister_current_thread() {
|
||||||
unsafe { GC_unregister_my_thread() }
|
unsafe { GC_unregister_my_thread() };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a garbage collection forcibly.
|
/// Runs a garbage collection forcibly.
|
||||||
@@ -126,7 +102,15 @@ impl Allocator {
|
|||||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||||
client_data: *const c_void,
|
client_data: *const c_void,
|
||||||
) {
|
) {
|
||||||
unsafe { GC_register_finalizer(ptr, finalizer, client_data, null(), null()) };
|
unsafe {
|
||||||
|
GC_register_finalizer(
|
||||||
|
ptr.cast_mut(),
|
||||||
|
Some(finalizer),
|
||||||
|
client_data.cast_mut(),
|
||||||
|
null_mut(),
|
||||||
|
null_mut(),
|
||||||
|
)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"autogen",
|
"autogen",
|
||||||
"autotools",
|
"autotools",
|
||||||
"bdwgc",
|
"bdwgc",
|
||||||
|
"bindgen",
|
||||||
"canonicalize",
|
"canonicalize",
|
||||||
"cflag",
|
"cflag",
|
||||||
"clippy",
|
"clippy",
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
"gcollect",
|
"gcollect",
|
||||||
"libatomic",
|
"libatomic",
|
||||||
"libc",
|
"libc",
|
||||||
|
"libclang",
|
||||||
"realloc",
|
"realloc",
|
||||||
"repr",
|
"repr",
|
||||||
"rustc",
|
"rustc",
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ edition = "2024"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../.." }
|
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ edition = "2024"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../.." }
|
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ edition = "2024"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../.." }
|
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ edition = "2024"
|
|||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../.." }
|
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
||||||
|
|||||||
Reference in New Issue
Block a user