Sean Colin Roach
Sean Colin Roach

Reputation: 33

Rust: How do I actually enable `#[cfg(no_global_oom_handling)]`?

So, laced throughout alloc and std methods are marked with #[cfg(not(no_global_oom_handling))], primarily methods that perform allocations where the case of running out of memory is handled via panicking. I've been researching all morning on how to use alloc with that flag enabled. I've gone down a few rabbit holes, such as build-std, but I've come up blank.

Note: I'm aware of the implications; this isn't a question of if I should or shouldn't, only a question of how to enable no_global_oom_handling?

Does anyone know how actually to enable this feature? I'm surprised it's not documented everywhere, even its tracking issue.

Upvotes: 1

Views: 941

Answers (2)

George
George

Reputation: 2801

For vscode you can edit the settings.json and edit an associated configuration setting. Here the key is the cfg name, such as "feature", while the value is a string such as, "ssr" as follows:

"rust-analyzer.cargo.cfgs": {
   "config_name": "config_setting",
   ...
}

for example,

"rust-analyzer.cargo.cfgs": {
   "feature": "ssr"
}

(not sure how to set multiple values such as multiple features this way, however and no time to investigate further).

Upvotes: 0

kmdreko
kmdreko

Reputation: 60082

You would need to pass a --cfg option. Either as arguments if using rustc directly, or in a RUSTFLAGS environment variable or build.rustflags configuration option in .cargo/config.toml when using Cargo.

An example (including build-std):

RUSTFLAGS="--cfg no_global_oom_handling" cargo +nightly run -Z build-std

See also: How to set cfg options to compile conditionally?

Upvotes: 2

Related Questions