Skip to content

Instantly share code, notes, and snippets.

@ookiineko
Last active May 8, 2024 04:38
Show Gist options
  • Save ookiineko/fcea30dd6ee01e160d796b65d10bd071 to your computer and use it in GitHub Desktop.
Save ookiineko/fcea30dd6ee01e160d796b65d10bd071 to your computer and use it in GitHub Desktop.
msys rust (unofficial) test (hacky)

first get cygwin rust (unofficial) from here (we will reconfigure it for linking against msys DLL instead of cygwin)

make sure you have gcc install for msys environment and run these in the MINGW64 terminal

Hello world:

export PATH=/path/to/cygwin-rust/bin:$PATH

cargo new --bin hellohi && cd hellohi
# must be called x86_64-pc-cygwin.json! (i.e. don't change the file name!)
rustc -Z unstable-options --target=x86_64-pc-cygwin --print target-spec-json > x86_64-pc-cygwin.json
patch -p1 -i path/to/x86_64-pc-cygwin.json.diff
# must place the json under the current directory!
cargo build --target=x86_64-pc-cygwin.json
# don't get tricked by the target name, it's now linked against msys-2.0.dll!
ldd ./target/x86_64-pc-cygwin/debug/hellohi.exe
./target/x86_64-pc-cygwin/debug/hellohi.exe

should give:

           ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ff9535d0000)
           KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ff9530c0000)
           KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ff950ad0000)
           msys-2.0.dll => /usr/bin/msys-2.0.dll (0x180040000)
Hello, world!
--- a/x86_64-pc-cygwin.json 2024-05-05 13:19:53.530699500 +0800
+++ b/x86_64-pc-cygwin.json 2024-05-05 13:17:47.610426400 +0800
@@ -12,27 +12,26 @@
"emit-debug-gdb-scripts": false,
"exe-suffix": ".exe",
"function-sections": false,
- "is-builtin": true,
"is-like-windows": true,
"late-link-args": {
"gcc": [
- "-lcygwin",
+ "-lmsys-2.0",
"-lgcc",
- "-lcygwin",
+ "-lmsys-2.0",
"-luser32",
"-lkernel32"
],
"ld": [
- "-lcygwin",
+ "-lmsys-2.0",
"-lgcc",
- "-lcygwin",
+ "-lmsys-2.0",
"-luser32",
"-lkernel32"
],
"ld.lld": [
- "-lcygwin",
+ "-lmsys-2.0",
"-lgcc",
- "-lcygwin",
+ "-lmsys-2.0",
"-luser32",
"-lkernel32"
]
@@ -62,7 +61,7 @@
"-l:libpthread.a"
]
},
- "linker": "x86_64-pc-cygwin-gcc",
+ "linker": "x86_64-pc-msys-gcc",
"llvm-target": "x86_64-unknown-windows-cygnus",
"max-atomic-width": 64,
"os": "cygwin",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment