Skip to content

Instantly share code, notes, and snippets.

@ookiineko
Last active May 5, 2024 04:45
Show Gist options
  • Save ookiineko/057eb3a91825313caeaf6d793a33b0b2 to your computer and use it in GitHub Desktop.
Save ookiineko/057eb3a91825313caeaf6d793a33b0b2 to your computer and use it in GitHub Desktop.
Cygwin Rust porting

an experimental Rust port for Cygwin

20240505 Update

cross compiling cygwin rust program right on windows from mingw (in msys2)

via msys2-cygwin (unoffical)

experimental toolchain downloadable from (note u will need cross gcc from msys2-cygwin (unoffical) to use it): https://github.com/ookiineko-cygport/rust/releases

image

Hello world

image

Pthreads demo

image

ripgrep

image image

latest(20240409) magiskboot on Cygwin

Get cross compiler at https://copr.fedorainfracloud.org/coprs/yselkowitz/cygwin/

build deps from src or steal sysroot from an existing cygwin install

To cross-compile Rust programs (for example magiskboot) u need these in your ~/.cargo/config.toml

[patch.crates-io]
libc_0_2_135 = { git = 'https://github.com/ookiineko-cygport/libc.git', package = 'libc', branch = '0.2.135' }
libc_0_2_148 = { git = 'https://github.com/ookiineko-cygport/libc.git', package = 'libc', branch = '0.2.148' }
libc_0_2_152 = { git = 'https://github.com/ookiineko-cygport/libc.git', package = 'libc', branch = '0.2.152' }
libc_0_2_153 = { git = 'https://github.com/ookiineko-cygport/libc.git', package = 'libc', branch = '0.2.153' }
cc_1_0_77 = { git = 'https://github.com/ookiineko-cygport/cc-rs.git', package = 'cc', branch = '1.0.77' }
cc_1_0_83 = { git = 'https://github.com/ookiineko-cygport/cc-rs.git', package = 'cc', branch = '1.0.83' }
compiler_builtins = { git = 'https://github.com/ookiineko-cygport/compiler-builtins.git' }
getrandom0_2_0 = { git = 'https://github.com/ookiineko-cygport/getrandom.git', package = 'getrandom', branch = '0.2.0' }
getrandom0_2_10 = { git = 'https://github.com/ookiineko-cygport/getrandom.git', package = 'getrandom', branch = '0.2.10' }
getrandom0_2_12 = { git = 'https://github.com/ookiineko-cygport/getrandom.git', package = 'getrandom', branch = '0.2.12' }
socket2 = { git = 'https://github.com/ookiineko-cygport/socket2.git' }
psm = { git = 'https://github.com/ookiineko-cygport/stacker.git' }
mio = { git = 'https://github.com/ookiineko-cygport/mio.git' }
tokio = { git = 'https://github.com/ookiineko-cygport/tokio.git' }
libloading_0_7_1 = { git = 'https://github.com/ookiineko-cygport/rust_libloading.git', package = 'libloading', branch = '0.7.1' }
libloading_0_7_3 = { git = 'https://github.com/ookiineko-cygport/rust_libloading.git', package = 'libloading', branch = '0.7.3' }
openssl-src = { git = 'https://github.com/ookiineko-cygport/openssl-src-rs.git' }
os_info = { git = 'https://github.com/ookiineko-cygport/os_info.git' }
cmake = { git = 'https://github.com/ookiineko-cygport/cmake-rs.git' }
ctest2 = { git = 'https://github.com/ookiineko-cygport/ctest2.git' }

this is needed bcs most crates doesn't support Cygwin and we have to patch them.

download magiskboot source from https://github.com/ookiineko/magiskboot_build, checkout to de80176321a4ed7086e6dcfb0127f8f28c1a23e3

remember to downgrade a few crates that require newer rustc version

Cargo

building

image

running

image

after os_info was fixed

image

ctest2 (libc-test wip)

some random tests

image

UPDATE 20240304: passing libc-test and a rustc.exe

image

image

Problem: LLVM unable to initialize in native rustc

Bugs

  • panic (stacktrace) sometimes not working

See also

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