Ada Compiler

Strikes me as the right approach to get started. Can even be continued long-term if you don’t care about Haiku as a build machine. But I would guess building on Haiku would be preferred for most.

I’ve been playing around with this - GNAT runs natively, and can compile simple programs:


(the --sysroot stuff is because I configured it wrong when cross-compiling)

It should now be just a matter of getting it to self-host, writing the proper run-time system definitions (I’m using the dummy ones for now) and packaging it up. Annoyingly, I can’t seem to cross-compile GCC (from the binutils repo, + my GNAT patches) with C++ support; the build fails while building libsupc++ and I’m not sure why (example session). Building without C++ support succeeds and yields a working compiler, as seen in the picture above, but I can’t use that to compile GCC itself. I am not sure what to try at this point.

I’ve put up my patches and rather messy build scripts here in case anybody wants to take a look, largely stolen from Haiku’s build scripts and elsewhere. You’ll need a somewhat contemporary GNAT version to build it - AdaCore GNAT 2021 is known to work, FSF GNAT 10.2 also does if you’re willing to gut the compiler source; FSF GNAT 11 should, but I haven’t tried. Check the environment variables in env.sh, then source/run all.sh - disable c++ on target-gnat.sh for a successful build, resume from any step by sourcing env.sh at least once followed by the appropriate shell script.

4 Likes

Thank you very much, I’ve been looking for this for a while!
I have tried your scripts under Debian 11.5 and i am stuck at the patching step.
buildtools and haiku have been downloaded under the gnat-haiku directory where the scripts are.

Sorry, the GNAT patch I had committed was relative to the buildtools repository root, rather than the GCC source directory; the one I just pushed should be fine.

Stuck at “cross-gnat.sh”, no problem with previous steps.
Don’t understand why it cannot find “Is_UTF_32_NKKC” which is defined in the package system system.UTF_32 from “buildtools\gcc\gcc\libgnat\s-utf_32.ads”
Using gnat 10.2 under debian though, not AdaCore Gnat 2021. Will try with FSF GNAT 11 when I have time.

Sorry, I probably should have been more explicit, but this is what I meant by “gutting the compiler source”. It is looking for Is_UTF_32_NFKC in your host, but that was introduced sometime after GNAT 10 (11.1, it seems?); patching out the check on scng.adb (as well as 2 or 3 other similar cases) should yield a working, if slightly crippled compiler, which you can then use to build an unpatched one. Otherwise you’ll probably have better luck with GNAT 11, although I haven’t tried it myself.

I am not surprised. I first saw “gcc 10.2.1” in your “example session” and forgot the fact that you used AdaCore GNAT 2021 which is in some ways different from the gcc version. My bad here.

Update:
Just confirming that I was successful compiling under KaOS (Arch Unix derivative if I am not wrong) with gcc 11.3

I managed to compile the whole thing with c,c++ and ada.

The problem was with the “-std=c++14” flag in “env.sh”
I guess the logic is that it forces c++14 at steps where it is not needed and when a “-sdt=something” is chosen -D__STRICT_ANSI__ is automatically defined. Getting rid of this flag option compiles the whole thing.

4 Likes

Fantastic! I had come across that post on the Gentoo forums pointing towards __STRICT_ANSI__, but hadn’t connected it to the -std=c++14 flag on CXXFLAGS (which I had blindly taken from Haiku’s build scripts); thank you!

I’ll play around with self-hosting the compiler on Haiku, then move away from the dummy runtime system definitions. Packaging this up will be interesting; I’m not sure it would be fine having GCC built from a binary seed (would it?), as PulkoMandy suggested, since it is kind of a core system component and whatnot; I imagine the proper way would be to have GNAT built together with the bootstrap packages here (I assume), but that would mean a bootstrap build now depends on a reasonably contemporaneous version of GNAT (would this be acceptable?).