Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a no_prefix feature #54

Merged
merged 1 commit into from
Jun 24, 2018
Merged

Add a no_prefix feature #54

merged 1 commit into from
Jun 24, 2018

Conversation

sfackler
Copy link
Collaborator

There are some targets that we still force a prefix since they have
issues when their libc malloc is replaced in this way.

Closes #39

There are some targets that we still force a prefix since they have
issues when their libc malloc is replaced in this way.

Closes gnzlbg#39
@gnzlbg gnzlbg merged commit 4f01b49 into gnzlbg:master Jun 24, 2018
@sfackler sfackler deleted the no-prefix branch June 24, 2018 19:35
@SimonSapin
Copy link
Contributor

I think it can be unexpected to silently use a prefix when the no_prefix feature is enabled. Shouldn’t the build script fail with an appropriate message in that case, to force users who would rely on this to do something platform-specific?

@gnzlbg
Copy link
Owner

gnzlbg commented Jun 24, 2018

I'm going to hold on a new release until @SimonSapin issues in the last two PRs are resolved. @SimonSapin mind you opening an issue?

@sfackler
Copy link
Collaborator Author

@SimonSapin my concern about failing the build is that there's no way to enable a feature on a target-specific basis IIRC, so if you want to have jemalloc replace libc malloc on Linux, you're not going to be able to run on OSX or whatever.

@SimonSapin
Copy link
Contributor

I was thinking of enabling the feature in a [target.'cfg(…)'.dependencies] section, but I wonder if that actually works in Cargo.

@gnzlbg
Copy link
Owner

gnzlbg commented Jun 24, 2018

my concern about failing the build is that there's no way to enable a feature on a target-specific basis IIRC

I think this is possible: https://github.com/gnzlbg/slice_deque/blob/master/Cargo.toml#L24

@SimonSapin
Copy link
Contributor

Depending on a crate or not at all based on cfg is possible.

I don’t know if conditionally enabling a feature based on cfg actually works or if the feature ends up being always enabled. I vaguely remember a Cargo bug like this but I couldn’t easily find it in the tracker and might be confusing it with something else.

@gnzlbg
Copy link
Owner

gnzlbg commented Jun 24, 2018

I vaguely remember a Cargo bug like this

Maybe rust-lang/cargo#4866 ?

There are issues with feature/dependency resolution when doing target specific things, but enabling/disabling the feature works IIRC.

@SimonSapin
Copy link
Contributor

I thought rust-lang/cargo#4866 wasn’t it based on the title and first message, but it does discuss [target.'cfg(…)'.dependencies] in later comments. So yeah, the scenario I had mind is indeed buggy in Cargo. The test case below enables both features.

Since conditionally-enabled feature doesn’t work, I suppose the best we can do is rename the feature to no_prefix_on_supported_platforms, or override_malloc_on_supported_platforms? https://github.com/alexcrichton/jemallocator/pull/56

Test case

Cargo.toml

[package]
name = "foo"
version = "0.1.0"

[dependencies]
a = {path = "./a"}

[target.'cfg(windows)'.dependencies]
a = {path = "./a", features = ["b"]}

[target.'cfg(unix)'.dependencies]
a = {path = "./a", features = ["c"]}

src/main.rs

extern crate a;

fn main() {
    a::b();
    a::c();
}

a/src/lib.rs

#[cfg(feature = "b")]
pub fn b() {}

#[cfg(feature = "c")]
pub fn c() {}

a/Cargo.toml

[package]
name = "a"
version = "0.1.0"

[features]
b = []
c = []

@sfackler
Copy link
Collaborator Author

Those feature names seem reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to let jemalloc overrides system allocator
3 participants