Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: support build and link dynamic library
  • Loading branch information
westhide committed Mar 30, 2025
commit f9e4a7033f58a802f1062675cb5bba4992391afc
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,10 @@ impl Build {
.arg(dst.join(dynlib_name))
.args(&objects);
run(cmd, &self.cargo_output)?;
} else {
self.assemble(lib_name, &dst.join(static_name), &objects)?;
}

self.assemble(lib_name, &dst.join(static_name), &objects)?;

let target = self.get_target()?;
if target.env == "msvc" {
let compiler = self.get_base_compiler()?;
Expand Down
31 changes: 31 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,37 @@ fn gnu_shared() {
test.cmd(0).must_have("-shared").must_not_have("-static");
}

#[test]
#[cfg(target_os = "linux")]
fn gnu_link_shared() {
use std::process::Command;

let output = Command::new("rustc").arg("-vV").output().unwrap();
let stdout_buf = String::from_utf8(output.stdout).unwrap();
let target = stdout_buf
.lines()
.find_map(|l| l.strip_prefix("host: "))
.unwrap();

reset_env();
let test = Test::gnu();
let root_dir = env!("CARGO_MANIFEST_DIR");
let src = format!("{root_dir}/dev-tools/cc-test/src/foo.c");

cc::Build::new()
.host(target)
.target(target)
.opt_level(2)
.out_dir(test.td.path())
.file(&src)
.shared_flag(true)
.static_flag(false)
.link_shared_flag(true)
.compile("foo");

assert!(test.td.path().join("libfoo.so").exists());
}

#[test]
fn gnu_flag_if_supported() {
reset_env();
Expand Down