Build custom libgc

This commit is contained in:
Yota Toyama
2019-04-26 03:31:56 +00:00
parent 9a689d5c00
commit cea904e618
13 changed files with 184 additions and 3 deletions

View File

@@ -5,7 +5,8 @@ jobs:
- image: rust - image: rust
steps: steps:
- run: apt -y update --fix-missing - run: apt -y update --fix-missing
- run: apt -y install libgc-dev - run: apt -y install cmake
- checkout - checkout
- run: git submodule update --init --recursive
- run: cargo build - run: cargo build
- run: cd examples && ./test.sh - run: cd examples && ./test.sh

6
.gitmodules vendored Normal file
View File

@@ -0,0 +1,6 @@
[submodule "vendor/bdwgc"]
path = vendor/bdwgc
url = https://github.com/raviqqe/bdwgc
[submodule "vendor/libatomic_ops"]
path = vendor/libatomic_ops
url = https://github.com/ivmai/libatomic_ops

26
Cargo.lock generated
View File

@@ -1,16 +1,42 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autotools"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "cc"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.51" version = "0.2.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "774fd1b2d459a939302a0bad631a3de176b8bd5f87cbfc28ceb1f6c18d731094"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
"checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"

View File

@@ -6,6 +6,11 @@ authors = ["swgillespie <sean.william.g@gmail.com>", "Yota Toyama <raviqqe@gmail
repository = "https://github.com/raviqqe/bdwgc-alloc" repository = "https://github.com/raviqqe/bdwgc-alloc"
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"
build = "build.rs"
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
[build-dependencies]
autotools = "0.2"
cmake = "0.1"

View File

@@ -4,7 +4,7 @@
[![Crate](https://img.shields.io/crates/v/bdwgc-alloc.svg?style=flat-square)](https://crates.io/crates/bdwgc-alloc) [![Crate](https://img.shields.io/crates/v/bdwgc-alloc.svg?style=flat-square)](https://crates.io/crates/bdwgc-alloc)
[![License](https://img.shields.io/github/license/raviqqe/bdwgc-alloc.svg?style=flat-square)](LICENSE) [![License](https://img.shields.io/github/license/raviqqe/bdwgc-alloc.svg?style=flat-square)](LICENSE)
[`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation for [bdwgc](https://github.com/ivmai/bdwgc), the conservative garbage collector. [`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation for [bdwgc](https://github.com/ivmai/bdwgc), the conservative garbage collector. This crate supports only Unix-like operating systems currently.
## Usage ## Usage

37
build.rs Normal file
View File

@@ -0,0 +1,37 @@
extern crate cmake;
const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops";
const LIB_GC_DIR: &str = "vendor/bdwgc";
fn main() {
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
std::process::Command::new("sh")
.arg("-c")
.arg(format!("cd {} && ./autogen.sh", dir))
.output()
.unwrap();
}
let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR)
.cflag("-fPIC")
.build();
println!(
"cargo:rustc-link-search=native={}",
dst.join("lib").display()
);
println!("cargo:rustc-link-lib=static=atomic_ops");
let dst = autotools::Config::new(LIB_GC_DIR)
.cflag(format!(
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC",
dst.join("include").display()
))
.build();
println!(
"cargo:rustc-link-search=native={}",
dst.join("lib").display()
);
println!("cargo:rustc-link-lib=static=gc");
}

View File

@@ -1,9 +1,19 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autotools"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -14,10 +24,26 @@ dependencies = [
"bdwgc-alloc 0.2.1", "bdwgc-alloc 0.2.1",
] ]
[[package]]
name = "cc"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.51" version = "0.2.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "774fd1b2d459a939302a0bad631a3de176b8bd5f87cbfc28ceb1f6c18d731094"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
"checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"

View File

@@ -1,12 +1,35 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autotools"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "cc"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "dynamic_threads" name = "dynamic_threads"
version = "0.1.0" version = "0.1.0"
@@ -20,4 +43,7 @@ version = "0.2.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "774fd1b2d459a939302a0bad631a3de176b8bd5f87cbfc28ceb1f6c18d731094"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
"checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"

View File

@@ -1,12 +1,35 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autotools"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "cc"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "gc_free" name = "gc_free"
version = "0.1.0" version = "0.1.0"
@@ -20,4 +43,7 @@ version = "0.2.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "774fd1b2d459a939302a0bad631a3de176b8bd5f87cbfc28ceb1f6c18d731094"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
"checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"

View File

@@ -1,12 +1,35 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autotools"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "bdwgc-alloc" name = "bdwgc-alloc"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "cc"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.51" version = "0.2.51"
@@ -20,4 +43,7 @@ dependencies = [
] ]
[metadata] [metadata]
"checksum autotools 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "774fd1b2d459a939302a0bad631a3de176b8bd5f87cbfc28ceb1f6c18d731094"
"checksum cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)" = "5e5f3fee5eeb60324c2781f1e41286bdee933850fff9b3c672587fed5ec58c83"
"checksum cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "96210eec534fc3fbfc0452a63769424eaa80205fda6cea98e5b61cb3d97bcec8"
"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" "checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917"

View File

@@ -13,7 +13,7 @@ struct GcStackBase {
reg_base: *const c_void, reg_base: *const c_void,
} }
#[link(name = "gc")] #[link(name = "gc", kind = "static")]
extern "C" { extern "C" {
fn GC_allow_register_threads() -> c_void; fn GC_allow_register_threads() -> c_void;
fn GC_free(ptr: *mut c_void); fn GC_free(ptr: *mut c_void);

1
vendor/bdwgc vendored Submodule

Submodule vendor/bdwgc added at 51a44b9cdb

1
vendor/libatomic_ops vendored Submodule

Submodule vendor/libatomic_ops added at 6287479564