-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
There is no cross-platform way to use include_*! #75075
Copy link
Copy link
Open
Labels
A-crossArea: Cross compilationArea: Cross compilationT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-crossArea: Cross compilationArea: Cross compilationT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Build scripts place their output in a folder created by Cargo. The path to it is passed in the environment variable
OUT_DIRboth to the build script and the main code. Since the file is placed in the directory, we need to add the path separator and then the name of the file. There seems to be no way to callinclude_bytes!with a platform-agnostic path separator, inserting/or\depending on the host OS.This works but is not portable:
include_bytes!(concat!(env!("OUT_DIR"), "/myfile"));This doesn't work:
include_bytes!(concat!(env!("OUT_DIR"), std::path::MAIN_SEPARATOR, "myfile"));becauseMAIN_SEPARATORis not a literal, andconcat!only eats literals.I've tried to to assemble a
Stringinconst fn, but that doesn't work either becauseString::push()requires a mutable borrow which are unsable inconst fn.#[cfg(unix)]and#[cfg(windows)]sort of work, but break on cross-compilation because thesecfgattributes look at the target OS, and we need to add a separator that works on the host OS.It's weird that this is either impossible to accomplish or the way to do so is very obscure. I'd expect this to be a relatively common operation.
rustc --version --verbose: