Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Meson naming convention #432

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ fn write_def_file<W: std::io::Write>(
/// Build import library for windows-gnu
fn build_implib_file(
ws: &Workspace,
build_targets: &BuildTargets,
name: &str,
target: &target::Target,
targetdir: &Path,
Expand Down Expand Up @@ -201,10 +202,7 @@ fn build_implib_file(
}
};

let lib_path = match flavor {
Flavor::Msvc => targetdir.join(format!("{name}.dll.lib")),
Flavor::Gnu => targetdir.join(format!("{name}.dll.a")),
};
let lib_path = build_targets.impl_lib.as_ref().unwrap();

let lib_file = cargo_util::paths::create(lib_path)?;
write_implib(lib_file, machine_type, flavor, &def_contents)?;
Expand Down Expand Up @@ -1200,7 +1198,7 @@ pub fn cbuild(
if !library_types.only_staticlib() && capi_config.library.import_library {
let lib_name = name;
build_def_file(ws, lib_name, &rustc_target, &root_output)?;
build_implib_file(ws, lib_name, &rustc_target, &root_output)?;
build_implib_file(ws, build_targets, lib_name, &rustc_target, &root_output)?;
}

if capi_config.header.enabled {
Expand Down
49 changes: 37 additions & 12 deletions src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ impl BuildTargets {
None
};

let Some(file_names) = FileNames::from_target(target, name, targetdir) else {
let Some(file_names) =
FileNames::from_target(target, name, targetdir, use_meson_naming_convention)
else {
return Err(anyhow::anyhow!(
"The target {}-{} is not supported yet",
target.os,
Expand Down Expand Up @@ -127,10 +129,18 @@ impl BuildTargets {
}

pub fn shared_output_file_name(&self) -> Option<OsString> {
if self.shared_lib.is_some() && self.use_meson_naming_convention {
Some(format!("lib{}.dll", self.name).into())
} else {
Some(self.shared_lib.as_ref()?.file_name().unwrap().to_owned())
match self.lib_type() {
LibType::Windows => {
if self.shared_lib.is_some()
&& self.use_meson_naming_convention
&& self.target.env == "gnu"
{
Some(format!("lib{}.dll", self.name).into())
} else {
Some(self.shared_lib.as_ref()?.file_name()?.to_owned())
}
}
_ => Some(self.shared_lib.as_ref()?.file_name()?.to_owned()),
}
}
}
Expand All @@ -145,7 +155,12 @@ struct FileNames {
}

impl FileNames {
fn from_target(target: &Target, lib_name: &str, targetdir: &Path) -> Option<Self> {
fn from_target(
target: &Target,
lib_name: &str,
targetdir: &Path,
use_meson_naming_convention: bool,
) -> Option<Self> {
let (shared_lib, static_lib, impl_lib, debug_info, def) = match target.os.as_str() {
"none" | "linux" | "freebsd" | "dragonfly" | "netbsd" | "android" | "haiku"
| "illumos" | "openbsd" | "emscripten" | "hurd" => {
Expand All @@ -164,13 +179,21 @@ impl FileNames {

if target.env == "msvc" {
let static_lib = targetdir.join(format!("{lib_name}.lib"));
let impl_lib = targetdir.join(format!("{lib_name}.dll.lib"));
let impl_lib = if use_meson_naming_convention {
targetdir.join(format!("{lib_name}.lib"))
} else {
targetdir.join(format!("{lib_name}.dll.lib"))
};
let pdb = Some(targetdir.join(format!("{lib_name}.pdb")));

(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
} else {
let static_lib = targetdir.join(format!("lib{lib_name}.a"));
let impl_lib = targetdir.join(format!("{lib_name}.dll.a"));
let impl_lib = if use_meson_naming_convention {
targetdir.join(format!("lib{lib_name}.dll.a"))
} else {
targetdir.join(format!("{lib_name}.dll.a"))
};
let pdb = None;

(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
Expand Down Expand Up @@ -215,7 +238,8 @@ mod test {
os: os.to_string(),
env: String::from(""),
};
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"));
let file_names =
FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/libferris.a"),
Expand All @@ -238,7 +262,8 @@ mod test {
os: os.to_string(),
env: String::from(""),
};
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"));
let file_names =
FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/libferris.a"),
Expand All @@ -260,7 +285,7 @@ mod test {
os: String::from("windows"),
env: String::from("msvc"),
};
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"));
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/ferris.lib"),
Expand All @@ -281,7 +306,7 @@ mod test {
os: String::from("windows"),
env: String::from("gnu"),
};
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"));
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/libferris.a"),
Expand Down
6 changes: 1 addition & 5 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
}
if capi_config.library.import_library {
let impl_lib = build_targets.impl_lib.as_ref().unwrap();
let impl_lib_name = if build_targets.use_meson_naming_convention {
format!("{}.lib", build_targets.name).into()
} else {
impl_lib.file_name().unwrap().to_owned()
};
let impl_lib_name = impl_lib.file_name().unwrap();
copy(ws, impl_lib, install_path_lib.join(impl_lib_name))?;
let def = build_targets.def.as_ref().unwrap();
let def_name = def.file_name().unwrap();
Expand Down
Loading