thepowersgang / mrustc

Alternative rust compiler (re-implementation)
MIT License
2.18k stars 109 forks source link

musl support #325

Closed lrvick closed 11 months ago

lrvick commented 12 months ago

Simple patch to add musl support.

There is no reliable way to detect musl I am aware of, but we can detect glibc which defines _USE_GNU, then we fall back to musl.

This successfully builds on alpine.

LMK if this approach works for you, and I can at least take a look at CI.

Linking #324

thepowersgang commented 11 months ago

Well, it passes CI. I assume that you've tested it with your own musl setup?

lrvick commented 11 months ago

It works in alpine's musl, though for some reason not with my own build of musl, which is likely a problem on my end I am currently debugging still.

 (50.0% 1r,0w,0b/2t): proc_macro v0.0.0
:0:0 warn:0:Multiple panic_runtime crates loaded - panic_abort-0_0_0 and panic_unwind-0_0_0
/usr/lib/gcc/x86_64-linux-musl/13.2.0/../../../../x86_64-linux-musl/bin/ld: output-1.54.0/libstd.rlib.o: in function `ZRG3cD15std0_0_0_H190003sys4unix5cvt_r2gCfG1c_AH18closureI_open_c_840g':
libstd.rlib.c:(.text.ZRG3cD15std0_0_0_H190003sys4unix5cvt_r2gCfG1c_AH18closureI_open_c_840g+0x41): undefined reference to `open64'
/usr/lib/gcc/x86_64-linux-musl/13.2.0/../../../../x86_64-linux-musl/bin/ld: output-1.54.0/libstd.rlib.o: in function `ZRG4cD15std0_0_0_H190003sys4unix2fs5lstat0g':
libstd.rlib.c:(.text.ZRG4cD15std0_0_0_H190003sys4unix2fs5lstat0g+0x8e): undefined reference to `lstat64'
collect2: error: ld returned 1 exit status
C Compiler failed to execute - error code 256
lrvick commented 11 months ago

Confirmed the above was related to gcc13 removing automatic includes of stdint, which was fixed in later versions of rust. We will need to backport a patch to make rust 1.54 libstd compile with gcc13 but a non issue for this PR.

I have now confirmed builds both in alpine and my own from-scratch musl-based distro with musl 1.2.4 and GCC12.