From 13617ed3787eadae52239f4d698481c09639238b Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 18 Feb 2016 19:10:00 +0300 Subject: [PATCH 1/4] remove je_ --- Cargo.toml | 1 + src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 5e7b909..57e6cc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ repository = "https://github.com/servo/heapsize" [features] unstable = [] +nightly = [] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e92aea7..195970e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ use std::rc::Rc; #[cfg(not(target_os = "windows"))] extern { + #![cfg_attr(feature = "nightly", link(name = "malloc_usable_size"))] // Get the size of a heap block. // // Ideally Rust would expose a function like this in std::rt::heap, which would avoid the From bf7f697d8283700f5dc6cf0afe8a6bfc18f89deb Mon Sep 17 00:00:00 2001 From: quininer kel Date: Fri, 19 Feb 2016 05:47:27 +0800 Subject: [PATCH 2/4] parse rustc version --- Cargo.toml | 6 +++++- build.rs | 31 +++++++++++++++++++++++++++++++ src/lib.rs | 6 +++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 57e6cc3..9d270a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,11 @@ authors = [ "The Servo Project Developers" ] description = "Infrastructure for measuring the total runtime size of an object on the heap" license = "MPL-2.0" repository = "https://github.com/servo/heapsize" +build = "build.rs" + +[build-dependencies] +semver = "0.2" +chrono = "0.2" [features] unstable = [] -nightly = [] \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..127f693 --- /dev/null +++ b/build.rs @@ -0,0 +1,31 @@ +extern crate semver; +extern crate chrono; + +use std::env::var; +use std::process::Command; +use semver::Version; +use chrono::NaiveDate; + +fn main() { + let unprefixed_jemalloc_version: Version = "1.8.0-dev".parse().unwrap(); + let unprefixed_jemalloc_day: NaiveDate = "2016-02-16".parse().unwrap(); + + let rustc_version_string = Command::new(var("RUSTC").unwrap_or("rustc".into())) + .arg("--version").output().ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .unwrap(); + let rustc_version: Version = rustc_version_string.split_whitespace() + .skip(1).next() + .and_then(|r| r.parse().ok()) + .unwrap(); + let rustc_day: NaiveDate = rustc_version_string.split_whitespace() + .last() + .and_then(|r| r[..r.len()-1].parse().ok()) + .unwrap(); + + if rustc_day < unprefixed_jemalloc_day + || rustc_version < unprefixed_jemalloc_version + { + println!("cargo:rustc-cfg=prefixed_jemalloc"); + } +} diff --git a/src/lib.rs b/src/lib.rs index 195970e..aef991e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ use std::rc::Rc; #[cfg(not(target_os = "windows"))] extern { - #![cfg_attr(feature = "nightly", link(name = "malloc_usable_size"))] + #[cfg_attr(any(prefixed_jemalloc, target_os = "macos", target_os = "android"), link_name = "je_malloc_usable_size")] // Get the size of a heap block. // // Ideally Rust would expose a function like this in std::rt::heap, which would avoid the @@ -30,7 +30,7 @@ extern { // platforms `JEMALLOC_USABLE_SIZE_CONST` is `const` and on some it is empty. But in practice // this function doesn't modify the contents of the block that `ptr` points to, so we use // `*const c_void` here. - fn je_malloc_usable_size(ptr: *const c_void) -> usize; + fn malloc_usable_size(ptr: *const c_void) -> usize; } /// A wrapper for je_malloc_usable_size that handles `EMPTY` and returns `usize`. @@ -43,7 +43,7 @@ pub unsafe fn heap_size_of(ptr: *const c_void) -> usize { if ptr == 0x01 as *const c_void { 0 } else { - je_malloc_usable_size(ptr) + malloc_usable_size(ptr) } } From 879ae75bea80096e14fdc1a7658003df08c13c38 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 22 Feb 2016 15:37:34 +0100 Subject: [PATCH 3/4] Simplify rustc version parsing --- Cargo.toml | 3 +-- build.rs | 39 +++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9d270a2..70391d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,7 @@ repository = "https://github.com/servo/heapsize" build = "build.rs" [build-dependencies] -semver = "0.2" -chrono = "0.2" +regex = "0.1" [features] unstable = [] diff --git a/build.rs b/build.rs index 127f693..5874b5a 100644 --- a/build.rs +++ b/build.rs @@ -1,31 +1,26 @@ -extern crate semver; -extern crate chrono; +extern crate regex; use std::env::var; use std::process::Command; -use semver::Version; -use chrono::NaiveDate; +use std::str; fn main() { - let unprefixed_jemalloc_version: Version = "1.8.0-dev".parse().unwrap(); - let unprefixed_jemalloc_day: NaiveDate = "2016-02-16".parse().unwrap(); - - let rustc_version_string = Command::new(var("RUSTC").unwrap_or("rustc".into())) - .arg("--version").output().ok() - .and_then(|o| String::from_utf8(o.stdout).ok()) - .unwrap(); - let rustc_version: Version = rustc_version_string.split_whitespace() - .skip(1).next() - .and_then(|r| r.parse().ok()) + let version_line = Command::new(var("RUSTC").unwrap_or("rustc".into())) + .arg("--version") + .output() + .unwrap() + .stdout; + let captures = regex::Regex::new(r"rustc (\d+)\.(\d+)\.(\d+).+(\d{4}-\d{2}-\d{2})\)") + .unwrap() + .captures(str::from_utf8(&version_line).unwrap()) .unwrap(); - let rustc_day: NaiveDate = rustc_version_string.split_whitespace() - .last() - .and_then(|r| r[..r.len()-1].parse().ok()) - .unwrap(); - - if rustc_day < unprefixed_jemalloc_day - || rustc_version < unprefixed_jemalloc_version - { + let version = ( + captures[1].parse::().unwrap(), + captures[2].parse::().unwrap(), + captures[3].parse::().unwrap(), + &captures[4], + ); + if version < (1, 8, 0, "2016-02-14") { println!("cargo:rustc-cfg=prefixed_jemalloc"); } } From 81db71eeda5fbce1573c51a1a3f35a6cf82f194e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 22 Feb 2016 15:38:04 +0100 Subject: [PATCH 4/4] Have Travis test on more Rust versions --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe7cfb8..6bbf80d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,18 @@ language: rust -rust: nightly +rust: + # Jemalloc prefixing change between these two versions + - nightly-2016-02-14 + - nightly-2016-02-17 + + - nightly + - beta + - stable + notifications: webhooks: http://build.servo.org:54856/travis script: - cargo test - - "[ $TRAVIS_RUST_VERSION = nightly ] || cargo test --features unstable" - - "[ $TRAVIS_RUST_VERSION = nightly ] || cargo test --manifest-path plugin/Cargo.toml" + - "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features unstable" + - "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --manifest-path plugin/Cargo.toml"