Skip to content

Commit 3e5f445

Browse files
committed
Implement option to use the Meson naming convention under MSVC
Fixes #280
1 parent df5e11c commit 3e5f445

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

src/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impl CPackage {
10201020

10211021
let install_paths = InstallPaths::new(name, args, rustc_target, &capi_config);
10221022
let build_targets =
1023-
BuildTargets::new(name, rustc_target, root_output, libkinds, &capi_config)?;
1023+
BuildTargets::new(name, rustc_target, root_output, libkinds, &capi_config, args.get_flag("meson"))?;
10241024

10251025
let finger_print = FingerPrint::new(&id, root_output, &build_targets, &install_paths);
10261026

@@ -1209,6 +1209,7 @@ pub fn cbuild(
12091209
&root_output,
12101210
&libkinds,
12111211
capi_config,
1212+
args.get_flag("meson")
12121213
)?;
12131214

12141215
if let (Some(from_static_lib), Some(to_static_lib)) = (

src/build_targets.rs

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn extra_targets(
4343

4444
#[derive(Debug, Clone)]
4545
pub struct BuildTargets {
46+
pub name: String,
4647
pub include: Option<PathBuf>,
4748
pub static_lib: Option<PathBuf>,
4849
pub shared_lib: Option<PathBuf>,
@@ -52,6 +53,7 @@ pub struct BuildTargets {
5253
pub pc: PathBuf,
5354
pub target: Target,
5455
pub extra: ExtraTargets,
56+
pub use_meson_naming_convention: bool,
5557
}
5658

5759
impl BuildTargets {
@@ -61,6 +63,7 @@ impl BuildTargets {
6163
targetdir: &Path,
6264
libkinds: &[&str],
6365
capi_config: &CApiConfig,
66+
use_meson_naming_convention: bool,
6467
) -> anyhow::Result<BuildTargets> {
6568
let pc = targetdir.join(format!("{}.pc", &capi_config.pkg_config.filename));
6669
let include = if capi_config.header.enabled {
@@ -139,6 +142,8 @@ impl BuildTargets {
139142
impl_lib,
140143
debug_info,
141144
def,
145+
use_meson_naming_convention,
146+
name: name.into(),
142147
target: target.clone(),
143148
extra: Default::default(),
144149
})

src/cli.rs

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct Common {
5050
#[clap(long = "crt-static")]
5151
/// Build the library embedding the C runtime
5252
crt_static: bool,
53+
#[clap(default_value = "false")]
54+
/// Use the Linux/Meson library naming convention on Windows
55+
meson: bool,
5356
}
5457

5558
fn base_cli() -> Command {

src/install.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,19 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
228228

229229
if let Some(ref static_lib) = build_targets.static_lib {
230230
ws.gctx().shell().status("Installing", "static library")?;
231-
copy(
232-
static_lib,
233-
install_path_lib.join(static_lib.file_name().unwrap()),
234-
)?;
231+
let lib_type = LibType::from_build_targets(build_targets);
232+
let file_name = match lib_type {
233+
LibType::Windows => {
234+
if build_targets.use_meson_naming_convention {
235+
format!("lib{}.a", build_targets.name).into()
236+
} else {
237+
static_lib.file_name().unwrap().to_owned()
238+
}
239+
}
240+
_ => static_lib.file_name().unwrap().to_owned(),
241+
};
242+
243+
copy(static_lib, install_path_lib.join(file_name))?;
235244
}
236245

237246
if let Some(ref debug_info) = build_targets.debug_info {
@@ -268,7 +277,11 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
268277
lib.install(capi_config, shared_lib, &install_path_lib)?;
269278
}
270279
LibType::Windows => {
271-
let lib_name = shared_lib.file_name().unwrap();
280+
let lib_name = if build_targets.use_meson_naming_convention {
281+
format!("lib{}.dll", build_targets.name).into()
282+
} else {
283+
shared_lib.file_name().unwrap().to_owned()
284+
};
272285

273286
if capi_config.library.install_subdir.is_none() {
274287
let install_path_bin = append_to_destdir(destdir.as_deref(), &paths.bindir);
@@ -281,7 +294,11 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
281294
}
282295
if capi_config.library.import_library {
283296
let impl_lib = build_targets.impl_lib.as_ref().unwrap();
284-
let impl_lib_name = impl_lib.file_name().unwrap();
297+
let impl_lib_name = if build_targets.use_meson_naming_convention {
298+
format!("{}.lib", build_targets.name).into()
299+
} else {
300+
impl_lib.file_name().unwrap().to_owned()
301+
};
285302
copy(impl_lib, install_path_lib.join(impl_lib_name))?;
286303
let def = build_targets.def.as_ref().unwrap();
287304
let def_name = def.file_name().unwrap();

0 commit comments

Comments
 (0)