Skip to content

Commit f9e4a70

Browse files
committed
feat: support build and link dynamic library
1 parent 1e8de34 commit f9e4a70

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,10 @@ impl Build {
14341434
.arg(dst.join(dynlib_name))
14351435
.args(&objects);
14361436
run(cmd, &self.cargo_output)?;
1437+
} else {
1438+
self.assemble(lib_name, &dst.join(static_name), &objects)?;
14371439
}
14381440

1439-
self.assemble(lib_name, &dst.join(static_name), &objects)?;
1440-
14411441
let target = self.get_target()?;
14421442
if target.env == "msvc" {
14431443
let compiler = self.get_base_compiler()?;

tests/test.rs

+31
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,37 @@ fn gnu_shared() {
354354
test.cmd(0).must_have("-shared").must_not_have("-static");
355355
}
356356

357+
#[test]
358+
#[cfg(target_os = "linux")]
359+
fn gnu_link_shared() {
360+
use std::process::Command;
361+
362+
let output = Command::new("rustc").arg("-vV").output().unwrap();
363+
let stdout_buf = String::from_utf8(output.stdout).unwrap();
364+
let target = stdout_buf
365+
.lines()
366+
.find_map(|l| l.strip_prefix("host: "))
367+
.unwrap();
368+
369+
reset_env();
370+
let test = Test::gnu();
371+
let root_dir = env!("CARGO_MANIFEST_DIR");
372+
let src = format!("{root_dir}/dev-tools/cc-test/src/foo.c");
373+
374+
cc::Build::new()
375+
.host(target)
376+
.target(target)
377+
.opt_level(2)
378+
.out_dir(test.td.path())
379+
.file(&src)
380+
.shared_flag(true)
381+
.static_flag(false)
382+
.link_shared_flag(true)
383+
.compile("foo");
384+
385+
assert!(test.td.path().join("libfoo.so").exists());
386+
}
387+
357388
#[test]
358389
fn gnu_flag_if_supported() {
359390
reset_env();

0 commit comments

Comments
 (0)