Skip to content

Add Cygwin support#500

Merged
lu-zero merged 2 commits into
lu-zero:masterfrom
lazka:cygwin-support
Nov 4, 2025
Merged

Add Cygwin support#500
lu-zero merged 2 commits into
lu-zero:masterfrom
lazka:cygwin-support

Conversation

@lazka
Copy link
Copy Markdown
Contributor

@lazka lazka commented Nov 3, 2025

Things are like with Windows+gnu, except the "meson-paths" logic is always used, and shared libs are prefixed with "cyg".

Things are like with Windows+gnu, except the "meson-paths"
logic is always used, and shared libs are prefixed with "cyg".
@lazka
Copy link
Copy Markdown
Contributor Author

lazka commented Nov 3, 2025

For reference:

$ rustc --print cfg --target x86_64-pc-cygwin
debug_assertions
panic="unwind"
target_abi=""
target_arch="x86_64"
target_endian="little"
target_env=""
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="cygwin"
target_pointer_width="64"
target_vendor="pc"
unix
$ cargo cinstall --destdir dest
$ tree dest
dest
└── usr
    └── local
        ├── bin
        │   └── cygmylib.dll
        ├── include
        │   └── mylib
        │       └── mylib.h
        └── lib
            ├── libmylib.a
            ├── libmylib.dll.a
            ├── mylib.def
            └── pkgconfig
                └── mylib.pc
$ c++ main.c -Idest/usr/local/include/mylib -Ldest/usr/local/lib -lmylib
$ PATH=dest/usr/local/bin:$PATH ./a.exe
hello world from rust!

Comment thread src/build_targets.rs
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.

Copy link
Copy Markdown
Contributor

@nirbheek nirbheek left a comment

Choose a reason for hiding this comment

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

lgtm overall

Comment thread src/build_targets.rs

let expected = FileNames {
static_lib: PathBuf::from("/foo/bar/libferris.a"),
shared_lib: PathBuf::from("/foo/bar/ferris.dll"),
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.

Suggested change
shared_lib: PathBuf::from("/foo/bar/ferris.dll"),
shared_lib: PathBuf::from("/foo/bar/cygferris.dll"),

No?

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.

Then the test needs this fix.

Copy link
Copy Markdown
Contributor Author

@lazka lazka Nov 3, 2025

Choose a reason for hiding this comment

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

As far as I understood it that's the filename that rustc creates, before it gets copied to the right name via cinstall (and the import lib gets re-created then), and I don't know where I could change that (??). Same as with mingw currently.

Copy link
Copy Markdown
Contributor Author

@lazka lazka Nov 3, 2025

Choose a reason for hiding this comment

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

I've reverted this for now. If shared_lib is supposed to be the final DLL name, and not the one rustc produces, then I think it should also be changed for windows+mingw.

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.

If the test confirms then we are set (and probably we should document more the struct to not be confused in the future :)

@lu-zero
Copy link
Copy Markdown
Owner

lu-zero commented Nov 3, 2025

@lazka is it difficult to add a CI item to test it?

@lu-zero
Copy link
Copy Markdown
Owner

lu-zero commented Nov 3, 2025

@lazka also can you reset the PR with the fix folded in?

@lazka
Copy link
Copy Markdown
Contributor Author

lazka commented Nov 3, 2025

I'll have a look later today.

Upstream Cygwin doesn't have a rust build yet (WIP) so use MSYS2
which ships rust for the Cygwin target.

For the example project don't run tests as those depend on inline-c
which depends on target-lexicon v0.11, while 0.13.3 is needed
for Cygwin support. /usr/local is not in the default pkgconf search
path, so add it.

Add separate jobs to avoid complicating the conditions of the existing
matrix setup even more.
@lazka
Copy link
Copy Markdown
Contributor Author

lazka commented Nov 3, 2025

I added some basic tests (see commit for details). I went for separate jobs as mixing in even more conditions seemed hard to follow, but I'd be happy to give it a try though if wanted.

Copy link
Copy Markdown
Contributor

@amyspark amyspark left a comment

Choose a reason for hiding this comment

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

LGTM

@lu-zero lu-zero merged commit 5fb145d into lu-zero:master Nov 4, 2025
19 checks passed
@nirbheek
Copy link
Copy Markdown
Contributor

nirbheek commented Nov 4, 2025

I guess we need an integration test that will check the names of the on-disk files after installation.

@lazka
Copy link
Copy Markdown
Contributor Author

lazka commented Nov 4, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants