diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 37d1b95d..8d95884d 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["cdylib"] [build-dependencies] cc = "*" -built = "*" +built = { version = "*", features = ["git2"] } bindgen = "*" [profile.release] diff --git a/mmtk/api/mmtk.h b/mmtk/api/mmtk.h index 30860b11..52437cc4 100644 --- a/mmtk/api/mmtk.h +++ b/mmtk/api/mmtk.h @@ -50,6 +50,7 @@ extern void mmtk_runtime_panic(void); extern void mmtk_unreachable(void); extern unsigned char mmtk_pin_object(void* obj); extern bool mmtk_is_pinned(void* obj); +extern const char* get_mmtk_version(void); extern void mmtk_set_vm_space(void* addr, size_t size); extern void mmtk_immortal_region_post_alloc(void* addr, size_t size); diff --git a/mmtk/build.rs b/mmtk/build.rs index 7428f03d..b8adc648 100644 --- a/mmtk/build.rs +++ b/mmtk/build.rs @@ -67,4 +67,6 @@ fn main() { bindings .write_to_file("src/julia_types.rs") .expect("Couldn't write bindings!"); + + built::write_built_file().expect("Failed to acquire build-time information"); } diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index edfb770a..c5f5942c 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -504,3 +504,10 @@ pub extern "C" fn mmtk_unpin_object(_object: ObjectReference) -> bool { pub extern "C" fn mmtk_is_pinned(_object: ObjectReference) -> bool { false } + +#[no_mangle] +pub extern "C" fn get_mmtk_version() -> *const c_char { + crate::build_info::MMTK_JULIA_FULL_VERSION_STRING + .as_c_str() + .as_ptr() as _ +} diff --git a/mmtk/src/build_info.rs b/mmtk/src/build_info.rs new file mode 100644 index 00000000..08365bea --- /dev/null +++ b/mmtk/src/build_info.rs @@ -0,0 +1,18 @@ +use std::ffi::CString; + +mod raw { + // The include imports a full list of the constants in built.rs from https://docs.rs/built/latest/built/index.html + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +lazy_static! { + // Owned string for the binding version, such as MMTk Julia 0.14.0 (cfc755f-dirty) + static ref BINDING_VERSION_STRING: String = match (raw::GIT_COMMIT_HASH, raw::GIT_DIRTY) { + (Some(hash), Some(dirty)) => format!("Built with MMTk Julia {} ({}{})", raw::PKG_VERSION, hash.split_at(7).0, if dirty { "-dirty" } else { "" }), + (Some(hash), None) => format!("Built with MMTk Julia {} ({}{})", raw::PKG_VERSION, hash.split_at(7).0, "-?"), + _ => format!("Built with MMTk Julia {}", raw::PKG_VERSION), + }; + // Owned string for both binding and core version. + #[derive(Debug)] + pub static ref MMTK_JULIA_FULL_VERSION_STRING: CString = CString::new(format!("{}, using {}", *BINDING_VERSION_STRING, *mmtk::build_info::MMTK_FULL_BUILD_INFO)).unwrap(); +} diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index 78e8bebf..429796fb 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -17,6 +17,7 @@ use std::sync::{Arc, Condvar, Mutex, RwLock}; pub mod active_plan; pub mod api; +mod build_info; pub mod collection; pub mod object_model; pub mod reference_glue;