rust-lang / rustc_codegen_gcc

libgccjit AOT codegen for rustc
Apache License 2.0
893 stars 61 forks source link

Can't build sysroot #525

Open hhamud opened 1 month ago

hhamud commented 1 month ago

Can't build sysroot with mac m1.

I've already tried to run clean all and then prepare again but it failed.

https://pastebin.com/EVp68ZxA

antoyo commented 1 month ago

What is your linker? Is it clang?

hhamud commented 1 month ago

What is your linker? Is it clang?

yeah

user@192 rustc_codegen_gcc % clang --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
antoyo commented 1 month ago

From what I can see in your logs, it seems there was a _ (underscore) prepended to the function names like _gcc_jit_type_dyncast_vector. I'm not familiar with macOS: do you know if this is something that happens on this OS?

hhamud commented 1 month ago

From what I can see in your logs, it seems there was a _ (underscore) prepended to the function names like _gcc_jit_type_dyncast_vector. I'm not familiar with macOS: do you know if this is something that happens on this OS?

it looks like it does.

How do I run the gcc backend with this flag? -fno-leading-underscore

antoyo commented 1 month ago

Set this environment variable before building the sysroot CG_RUSTFLAGS=-Cllvm-args=-fno-leading-underscore.

hhamud commented 1 month ago

Set this environment variable before building the sysroot CG_RUSTFLAGS=-Cllvm-args=-fno-leading-underscore.

I still get the same problem when running these commands to try again

CG_RUSTFLAGS=-Cllvm-args=-fno-leading-underscore ./y.sh clean all
CG_RUSTFLAGS=-Cllvm-args=-fno-leading-underscore ./y.sh prepare
CG_RUSTFLAGS=-Cllvm-args=-fno-leading-underscore ./y.sh build sysroot --release

I think it might just be a compatibility issue with the arm architecture.

antoyo commented 1 month ago

I just looked back at your logs and it's actually not the sysroot that you cannot build, it's rustc_codegen_gcc itself. How did you build libgccjit?

Since I was able to build the sysroot on a Mac M1 with Asahi Linux, I believe this is related to macOS and not the hardware.

I believe this is more related to macOS ABI, so perhaps you built libgccjit with the wrong ABI?

hhamud commented 1 month ago

I just looked back at your logs and it's actually not the sysroot that you cannot build, it's rustc_codegen_gcc itself. How did you build libgccjit?

Since I was able to build the sysroot on a Mac M1 with Asahi Linux, I believe this is related to macOS and not the hardware.

I believe this is more related to macOS ABI, so perhaps you built libgccjit with the wrong ABI?

I just copied the config.toml file as shown in the example and it downloaded that when I ran the commands.

GuillaumeGomez commented 1 month ago

I think it's why it doesn't work: it's compiled for linux. You need to build gcc yourself to be able to use it.

hhamud commented 1 month ago

I think it's why it doesn't work: it's compiled for linux. You need to build gcc yourself to be able to use it.

ok I will try out cloning gcc and follow the instructions to compile it myself.

hhamud commented 1 month ago

I got an error when following the gcc instructions to compile my own libgccjit.

after following these steps but converting them into macos supported packages and instructions.

$ git clone https://github.com/antoyo/gcc

$ cd gcc

$ brew install flex mpfr gmp libmpc

$ mkdir gcc-build gcc-install

$ cd gcc-build

$ ../gcc/configure \
    --enable-host-shared \
    --enable-languages=jit \
    --enable-checking=release \
    --disable-bootstrap \
    --disable-multilib \
    --prefix=$(pwd)/../gcc-install \

I got this error

*** Configuration aarch64-apple-darwin22.6.0 not supported

Update:

I have found a mac os compatible gcc repo, I just need to apply antoyo's patch to this and I will be all set. The diff is too large and I don't know enough on how gcc works to apply it appropriately.

@antoyo can you make a note in the docs that macos is incompatible for the time being.

antoyo commented 4 weeks ago

Yes, I will add the note that macOS is currently incompatible.

Do you know how much the repo you found diverges from upstream? If there are not many changes, perhaps I could include the changes in my GCC fork.

hhamud commented 4 weeks ago

Yes, I will add the note that macOS is currently incompatible.

Do you know how much the repo you found diverges from upstream? If there are not many changes, perhaps I could include the changes in my GCC fork.

I have the git diff between the two repos and its pretty chunky.

its uploaded here

https://file.io/K4Cwyuna6Oth

antoyo commented 4 weeks ago

Just to make sure, did you do the diff betwee these 2 repos:

?

hhamud commented 4 weeks ago

Just to make sure, did you do the diff betwee these 2 repos:

* https://github.com/gcc-mirror/gcc

* https://github.com/iains/gcc-darwin-arm64

?

no specifically your patched version.

antoyo commented 4 weeks ago

Ok, my fork is 2379 commits behind compared to upstream, so that might be why there are so many changes.

I was asking if you compared with https://github.com/gcc-mirror/gcc to know if it would be easy to add the changes required for macOS if I rebase my fork.

hhamud commented 4 weeks ago

Ok, my fork is 2379 commits behind compared to upstream, so that might be why there are so many changes.

I was asking if you compared with https://github.com/gcc-mirror/gcc to know if it would be easy to add the changes required for macOS if I rebase my fork.

ok here's the diff between master gcc and gcc-darwin-arm64 master-wip-apple-si

diff.patch