Skip to content
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
42 changes: 42 additions & 0 deletions .github/workflows/example-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,45 @@ jobs:
meson setup build
meson compile -C build
meson test -C build

example-project-cygwin:
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

steps:
- name: Clone Git repository
uses: actions/checkout@v5

- name: Install rust
uses: msys2/setup-msys2@v2
with:
update: true
msystem: MSYS
install: rust pkgconf gcc openssl-devel libopenssl make

- name: Install cargo-c applet
run: cargo install --path .

- name: Build C API for example project
working-directory: example-project
run: cargo cbuild --verbose --release

- name: Install into /usr/local
working-directory: example-project
run: cargo cinstall --verbose --release --prefix=/usr/local

- name: Test pkgconf
run: |
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
pkgconf --version
test "$(pkgconf --cflags example_project)" = "-I/usr/local/include/example-project-0.1"
test "$(pkgconf --libs example_project)" = "-L/usr/local/lib -lexample-project"

- name: Test usage from C (using Makefile)
working-directory: example-project/usage-from-c
run: |
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,29 @@ jobs:
run: |
cargo test --verbose

cygwin-test:
needs: rustfmt-clippy
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

steps:
- name: Clone Git repository
uses: actions/checkout@v5

- name: Install rust and dependencies
uses: msys2/setup-msys2@v2
with:
update: true
msystem: MSYS
install: rust openssl-devel libopenssl pkgconf

- name: Build
run: |
cargo build --verbose

- name: Run tests
run: |
cargo test --verbose
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn build_implib_file(
target: &target::Target,
targetdir: &Path,
) -> anyhow::Result<()> {
if target.os == "windows" {
if target.os == "windows" || target.os == "cygwin" {
ws.gctx().shell().status("Building", "implib")?;

let def_path = targetdir.join(format!("{name}.def"));
Expand Down
31 changes: 28 additions & 3 deletions src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ impl BuildTargets {
pub fn shared_output_file_name(&self) -> Option<OsString> {
match self.lib_type() {
LibType::Windows => {
if self.shared_lib.is_some()
if self.target.os == "cygwin" {
Some(format!("cyg{}.dll", self.name).into())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct. Cygwin has a different ABI, you cannot mix cygwin DLLs with any other runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if self.shared_lib.is_some()
&& self.use_meson_naming_convention
&& self.target.env == "gnu"
{
Expand Down Expand Up @@ -174,7 +176,7 @@ impl FileNames {
let pdb = Some(targetdir.join(format!("lib{lib_name}.dSYM")));
(shared_lib, static_lib, None, pdb, None)
}
"windows" => {
"windows" | "cygwin" => {
let shared_lib = targetdir.join(format!("{lib_name}.dll"));
let def = targetdir.join(format!("{lib_name}.def"));

Expand All @@ -190,7 +192,7 @@ impl FileNames {
(shared_lib, static_lib, Some(impl_lib), pdb, Some(def))
} else {
let static_lib = targetdir.join(format!("lib{lib_name}.a"));
let impl_lib = if use_meson_naming_convention {
let impl_lib = if use_meson_naming_convention || target.os == "cygwin" {
targetdir.join(format!("lib{lib_name}.dll.a"))
} else {
targetdir.join(format!("{lib_name}.dll.a"))
Expand Down Expand Up @@ -326,4 +328,27 @@ mod test {

assert_eq!(file_names.unwrap(), expected);
}

#[test]
fn cygwin() {
let target = Target {
is_target_overridden: false,
arch: String::from(""),
os: String::from("cygwin"),
env: String::from(""),
cfg: Vec::new(),
target: None,
};
let file_names = FileNames::from_target(&target, "ferris", Path::new("/foo/bar"), false);

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/libferris.a"),
shared_lib: PathBuf::from("/foo/bar/ferris.dll"),
impl_lib: Some(PathBuf::from("/foo/bar/libferris.dll.a")),
debug_info: None,
def: Some(PathBuf::from("/foo/bar/ferris.def")),
};

assert_eq!(file_names.unwrap(), expected);
}
}
2 changes: 1 addition & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl LibType {
| ("emscripten", _)
| ("hurd", _) => LibType::So,
("macos", _) | ("ios", _) | ("tvos", _) | ("visionos", _) => LibType::Dylib,
("windows", _) => LibType::Windows,
("windows", _) | ("cygwin", _) => LibType::Windows,
_ => unimplemented!("The target {}-{} is not supported yet", os, env),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Target {
lines.push(line);
// Enable larger LC_RPATH and install_name entries
lines.push("-Wl,-headerpad_max_install_names".to_string());
} else if os == "windows" && env == "gnu" {
} else if (os == "windows" && env == "gnu") || (os == "cygwin") {
// This is only set up to work on GNU toolchain versions of Rust
lines.push(format!(
"-Wl,--output-def,{}",
Expand Down
Loading