You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When called as a library, cargo is overwriting the build configuration of the target project.
I'm developing a "RustPacker" project which takes another Rust project (created via cargo new), edits some files and then compiles it.
The function responsible for compiling the target is the following:
fn compiler(path_to_cargo_project: &mut PathBuf) -> Result<(), Box<dyn std::error::Error>> {
path_to_cargo_project.push("Cargo.toml");
let absolute_toml_path = path_to_cargo_project.absolutize()?;
let config: Config = Config::default()?;
let ws = Workspace::new(&absolute_toml_path, &config)?;
let mut compile_options: CompileOptions = CompileOptions::new(&config , CompileMode::Build)?;
compile_options.build_config.requested_profile = InternedString::new("release");
compile(&ws, &compile_options)?;
Ok(())
}
Even if the target Rust project contains a ".cargo/config" file forcing build target as "x86_64-pc-windows-gnu", cargo attempts to build the project to Linux binary when run an a Linux box.
Steps
On a Linux box : install required dependencies cross-compilation to Windows (gcc, mingw64, Rust...)
Config starts probing .cargo/config.toml from current working directory1 and then up to root. This is documented in here. I guess that's why config file from a template never got read. Could you try switching working directory to where the temp template is before calling Config::default?
FWIW, there is a meta issue about config search. #10952 also deals with setting work directory before build gets started.
Config starts probing .cargo/config.toml from current working directory1 and then up to root. This is documented in here. I guess that's why config file from a template never got read. Could you try switching working directory to where the temp template is before calling Config::default?
FWIW, there is a meta issue about config search. #10952 also deals with setting work directory before build gets started.
Problem
When called as a library, cargo is overwriting the build configuration of the target project.
I'm developing a "RustPacker" project which takes another Rust project (created via
cargo new
), edits some files and then compiles it.The function responsible for compiling the target is the following:
Even if the target Rust project contains a ".cargo/config" file forcing build target as "x86_64-pc-windows-gnu", cargo attempts to build the project to Linux binary when run an a Linux box.
Steps
cargo run -- -f calc.bin -i ct
Same steps do work when run on a Windows box.
Full Rust backtrace:
Possible Solution(s)
As of today, I can circumvent the problem by:
cargo build
as an OS command instead of using cargo as a libraryNotes
The error was raised when using this project: https://github.com/Nariod/RustPacker
Version
The text was updated successfully, but these errors were encountered: