MCPcopy Create free account
hub / github.com/Nariod/RustPacker / compile_in_container

Function compile_in_container

src/compiler.rs:70–103  ·  view source on GitHub ↗
(
    runtime: &str,
    path_to_cargo_folder: &Path,
)

Source from the content-addressed store, hash-verified

68}
69
70fn compile_in_container(
71 runtime: &str,
72 path_to_cargo_folder: &Path,
73) -> Result<(), Box<dyn std::error::Error>> {
74 ensure_builder_image(runtime)?;
75
76 let abs_path = absolute_path(path_to_cargo_folder)?;
77 let mount = format!("{}:/build:z", abs_path.display());
78 let cache_mount = "rustpacker-cargo-cache:/usr/local/cargo/registry:z";
79
80 let output = Command::new(runtime)
81 .args(["run", "--rm"])
82 .args(["-v", &mount])
83 .args(["-v", cache_mount])
84 .args(["-e", "CFLAGS=-lrt"])
85 .args(["-e", "LDFLAGS=-lrt"])
86 .args(["-e", "RUSTFLAGS=-C target-feature=+crt-static"])
87 .arg(BUILDER_IMAGE)
88 .args(["cargo", "build", "--release", "--target", BUILD_TARGET])
89 .output()?;
90
91 if !output.status.success() {
92 let err = String::from_utf8_lossy(&output.stderr);
93 eprintln!("{}", err);
94 return Err(format!("Container compilation failed: {}", output.status).into());
95 }
96
97 if !output.stderr.is_empty() {
98 let warnings = String::from_utf8_lossy(&output.stderr);
99 println!("{}", warnings);
100 }
101
102 Ok(())
103}
104
105fn local_build_target() -> &'static str {
106 if cfg!(target_os = "windows") {

Callers 1

run_compilerFunction · 0.85

Calls 2

ensure_builder_imageFunction · 0.85
absolute_pathFunction · 0.85

Tested by

no test coverage detected