Skip to content

Commit 1cbed9e

Browse files
committed
Add Cygwin support
Things are like with Windows+gnu, except the "meson-paths" logic is always used, and shared libs are prefixed with "cyg".
1 parent 78a62e7 commit 1cbed9e

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn build_implib_file(
182182
target: &target::Target,
183183
targetdir: &Path,
184184
) -> anyhow::Result<()> {
185-
if target.os == "windows" {
185+
if target.os == "windows" || target.os == "cygwin" {
186186
ws.gctx().shell().status("Building", "implib")?;
187187

188188
let def_path = targetdir.join(format!("{name}.def"));

src/build_targets.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ impl BuildTargets {
131131
pub fn shared_output_file_name(&self) -> Option<OsString> {
132132
match self.lib_type() {
133133
LibType::Windows => {
134-
if self.shared_lib.is_some()
134+
if self.target.os == "cygwin" {
135+
Some(format!("cyg{}.dll", self.name).into())
136+
} else if self.shared_lib.is_some()
135137
&& self.use_meson_naming_convention
136138
&& self.target.env == "gnu"
137139
{
@@ -174,7 +176,7 @@ impl FileNames {
174176
let pdb = Some(targetdir.join(format!("lib{lib_name}.dSYM")));
175177
(shared_lib, static_lib, None, pdb, None)
176178
}
177-
"windows" => {
179+
"windows" | "cygwin" => {
178180
let shared_lib = targetdir.join(format!("{lib_name}.dll"));
179181
let def = targetdir.join(format!("{lib_name}.def"));
180182

@@ -190,7 +192,7 @@ impl FileNames {
190192
(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
191193
} else {
192194
let static_lib = targetdir.join(format!("lib{lib_name}.a"));
193-
let impl_lib = if use_meson_naming_convention {
195+
let impl_lib = if use_meson_naming_convention || target.os == "cygwin" {
194196
targetdir.join(format!("lib{lib_name}.dll.a"))
195197
} else {
196198
targetdir.join(format!("{lib_name}.dll.a"))
@@ -326,4 +328,27 @@ mod test {
326328

327329
assert_eq!(file_names.unwrap(), expected);
328330
}
331+
332+
#[test]
333+
fn cygwin() {
334+
let target = Target {
335+
is_target_overridden: false,
336+
arch: String::from(""),
337+
os: String::from("cygwin"),
338+
env: String::from(""),
339+
cfg: Vec::new(),
340+
target: None,
341+
};
342+
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);
343+
344+
let expected = FileNames {
345+
static_lib: PathBuf::from("/foo/bar/libferris.a"),
346+
shared_lib: PathBuf::from("/foo/bar/ferris.dll"),
347+
impl_lib: Some(PathBuf::from("/foo/bar/libferris.dll.a")),
348+
debug_info: None,
349+
def: Some(PathBuf::from("/foo/bar/ferris.def")),
350+
};
351+
352+
assert_eq!(file_names.unwrap(), expected);
353+
}
329354
}

src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl LibType {
107107
| ("emscripten", _)
108108
| ("hurd", _) => LibType::So,
109109
("macos", _) | ("ios", _) | ("tvos", _) | ("visionos", _) => LibType::Dylib,
110-
("windows", _) => LibType::Windows,
110+
("windows", _) | ("cygwin", _) => LibType::Windows,
111111
_ => unimplemented!("The target {}-{} is not supported yet", os, env),
112112
}
113113
}

src/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl Target {
133133
lines.push(line);
134134
// Enable larger LC_RPATH and install_name entries
135135
lines.push("-Wl,-headerpad_max_install_names".to_string());
136-
} else if os == "windows" && env == "gnu" {
136+
} else if (os == "windows" && env == "gnu") || (os == "cygwin") {
137137
// This is only set up to work on GNU toolchain versions of Rust
138138
lines.push(format!(
139139
"-Wl,--output-def,{}",

0 commit comments

Comments
 (0)