Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnat: init at 9 #62314

Merged
2 commits merged into from Apr 20, 2020
Merged

gnat: init at 9 #62314

2 commits merged into from Apr 20, 2020

Conversation

Lucus16
Copy link
Contributor

@Lucus16 Lucus16 commented May 31, 2019

Motivation for this change

Gnat is the Ada compiler frontend in gcc. It used to be in nixpkgs based on gcc 4.5 but it broke when the cc wrappers were rewritten. I've been trying to get it to work with gcc 9 and the current cc wrapper scripts. I think I've ported all relevant parts, but for now, it seems the configure script is not convinced it has a gnat compiler available. I'm having a hard time figuring out why.

Currently, this PR needs a rebuild of the world because it needs some additions in cc-wrapper/add-flags.sh. An alternative option is to give gnat its own add-flags variant.

I don't have the time to finish this right now, so help is appreciated.

TODO

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@yorickvP
Copy link
Contributor

@yorickvP
Copy link
Contributor

@GrahamcOfBorg build gnat

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

The configure script fails in this part

# Test for GNAT.
# We require the gnatbind & gnatmake programs, as well as a compiler driver
# that understands Ada.  We use the user's CC setting, already found, and
# possibly add $1 to the command-line parameters.
#
# Sets the shell variable have_gnat to yes or no as appropriate, and
# substitutes GNATBIND and GNATMAKE.
AC_DEFUN([ACX_PROG_GNAT],
[AC_REQUIRE([AC_CHECK_TOOL_PREFIX])
AC_REQUIRE([AC_PROG_CC])
AC_CHECK_TOOL(GNATBIND, gnatbind, no)
AC_CHECK_TOOL(GNATMAKE, gnatmake, no)
AC_CACHE_CHECK([whether compiler driver understands Ada],
		 acx_cv_cc_gcc_supports_ada,
[cat >conftest.adb <<EOF
procedure conftest is begin null; end conftest;
EOF
acx_cv_cc_gcc_supports_ada=no
# There is a bug in old released versions of GCC which causes the
# driver to exit successfully when the appropriate language module
# has not been installed.  This is fixed in 2.95.4, 3.0.2, and 3.1.
# Therefore we must check for the error message as well as an
# unsuccessful exit.
# Other compilers, like HP Tru64 UNIX cc, exit successfully when
# given a .adb file, but produce no object file.  So we must check
# if an object file was really produced to guard against this.
errors=`(${CC} $1[]m4_ifval([$1], [ ])-c conftest.adb) 2>&1 || echo failure`
if test x"$errors" = x && test -f conftest.$ac_objext; then
  acx_cv_cc_gcc_supports_ada=yes
fi
rm -f conftest.*])

if test "x$GNATBIND" != xno && test "x$GNATMAKE" != xno && test x$acx_cv_cc_gcc_supports_ada != xno; then
  have_gnat=yes
else
  have_gnat=no
fi
])

Apparently it desires that $CC can compile ADA and that doesn't hold? (the gnatbind and gnatmake checks do succeed) I don't know... I tried the gnatboot you added and cc didn't really work there, so perhaps that's the issue here?

$ cc -c hello.adb
gcc: error trying to exec 'gnat1': execvp: No such file or directory

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

cc is not from gnatboot, but rather from stdenv. I don't know about ${CC}. I couldn't figure out how this worked before.

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

Oh, the command above actually works if I add ${gnatboot.cc}/bin into $PATH, but the output from gnat build failure remains the same as far as I can see.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

I just checked, it seems that originally, CC=gcc and both gcc and cc both point into the gnatboot package. We'll need to figure out some way to have gnatboot override stdenv. I'm not sure if the stdenv C compiler is still needed, but some C will need to be compiled.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

NIX_CC still pointed to stdenv though.

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

Yes, I managed to fish the output from the test command:

gcc: error: conftest.adb: Ada compiler not installed on this system

I expect the build probably wouldn't work just with gnatboot itself.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

I checked with stdenvNoCC, it doesn't work.

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

That's not what I meant. I got

checking for clearerr_unlocked... configure: error: C++ compiler missing or inoperational

(the previously failing test for ADA working did succeed) The gnatboot from Gentoo seems not to support C++ (by looking at the files), but recent gcc versions are partially written in C++ and I suspect they can't automatically bootstrap without a C++ compiler.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

By placing gnatboot in front of the PATH in the preConfigure phase, we get a lot further.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

a-except.adb:860:42: missing argument for parameter "S" in call to "Image_Integer" declared at s-imgint.ads:39
make[3]: *** [../../gcc-9.1.0/gcc/ada/gcc-interface/Make-lang.in:1033: ada/libgnat/a-except.o] Error 1

Looks like an Ada error in the source, possibly because gnatboot is version 4.1 which might be too old to compile version 9.1.

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

Have you looked what bootstrap sequence for gnat is used elsewhere?

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

Applying the same approach to gnat6 leads even further – several minutes of compilation:

/nix/store/15vi6br717ndj6vd1cwqhc9pgvk2i5hy-binutils-2.31.1/bin/ld: cannot find crt1.o: No such file or directo
ry
/nix/store/15vi6br717ndj6vd1cwqhc9pgvk2i5hy-binutils-2.31.1/bin/ld: cannot find crti.o: No such file or directo
ry
collect2: error: ld returned 1 exit status
gnatlink: error when calling /build/build/gcc/xg++
make[3]: *** [../gcc-interface/Makefile:2626: common-tools] Error 4
make[3]: Leaving directory '/build/build/gcc/ada/tools'
make[2]: *** [Makefile:197: gnattools-native] Error 2
make[2]: Leaving directory '/build/build/gnattools'
make[1]: *** [Makefile:11308: all-gnattools] Error 2

Commit 8bd9463.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

I ported it and I'm currently investigating other errors. Will push later today.

@Lucus16
Copy link
Contributor Author

Lucus16 commented Jun 2, 2019

Just managed to build gnat6 using gcc6, but I will try to make it work using gcc7 for a bit.

@vcunat
Copy link
Member

vcunat commented Jun 2, 2019

I assumed that if the gentoo gnatboot could be used to build some gnat version that's not too old, that one should hopefully be sufficiently new to build gnat9 and hopefully even some future versions. (I tried 6 first for greater ease of modifications ATM due to gcc6 not being in stdenv bootstrap.)

@vcunat
Copy link
Member

vcunat commented Sep 5, 2019

Hmm, it still does not build for me: dhx6br4f0m3kjnlvmc59ph7cpg54h3sv-ghdl-llvm-0.36.log – perhaps we'll disable that variant for now?

@Lucus16
Copy link
Contributor Author

Lucus16 commented Sep 5, 2019

Looks like this is an instance of the intermittent build failure. It worked for me with 4 and with 8 cores. It might work if you try a few more times with --cores 1. Maybe we should just set enableParallelBuilding = false; on ghdl and gnat?

@FRidh FRidh added this to New in Staging Oct 24, 2019
@FRidh FRidh moved this from New to WIP in Staging Oct 24, 2019
@flokli
Copy link
Contributor

flokli commented Dec 22, 2019

If one derivation is flaky when building in parallel, setting enableParallelBuilding = false would be the right way.

Can you do that and rebase on top of latest staging?

As langAda doesn't default to true, and it mostly builds too, it'd probably be beneficial to have this in nixpkgs.

@flokli
Copy link
Contributor

flokli commented Dec 22, 2019

Btw, I'm not so sure about the state of that gnatboot distfile on the gentoo servers.

If we need to use binaries, what about something like that as bootstrap?
That seems to be what gentoo does nowadays, too.

{ stdenv
, fetchurl
, autoPatchelfHook
, ncurses5 }:

stdenv.mkDerivation {
  pname = "gnats-bootstrap";
  version = "2014";

  buildInputs = [
    ncurses5
  ];

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  src = fetchurl {
    name = "gnat-gpl-2014-x86_64-linux-bin.tar.gz";
    url = "https://community.download.adacore.com/v1/6eb6eef6bb897e4c743a519bfebe0b1d6fc409c6?filename=gnat-gpl-2014-x86_64-linux-bin.tar.gz";
    sha256 = "0cxpxbx3dnq6fsy4k3qil377znv8k13nn3xgfha9jmpm9p4shqw0";
  };

  buildPhase = ":";

  installPhase = ''
    mkdir -p $out
    cp -R . $out

    rm $out/bin/gps_exe
    rm -R $out/lib/python2.7/ $out/share/gdb-7.7/python-2.7.3 $out/lib/gtk-3.0 $out/lib/gps/gdk-pixbuf-2.0 $out/lib/gps $out/lib/libpyglib-gi-2.0-python.so.0.0.0
  '';
}

There are also binaries for a lot of architectures, more than on the gentoo mirrors.

@ghost
Copy link

ghost commented Jan 7, 2020

I've rebased this and was able to build a coreboot toolchain with Ada support, which is required for building coreboot with native graphics initialization for some boards.
Thanks for the work! My rebased version is available on the feature/gnat branch on my fork.

@sylv-io
Copy link
Contributor

sylv-io commented Apr 18, 2020

@Lucus16 first of all, thanks for this PR.
I also rebased it and was able to build the coreboot toolchain with this environment. I would love to see this PR merged. Do you have any plans to continue your work ?

@Lucus16
Copy link
Contributor Author

Lucus16 commented Apr 18, 2020

It's been a while since I've worked on this. I'll see if I can rebase on staging and build a few times to see if the intermittent build failure is still present.

@Lucus16 Lucus16 force-pushed the gnat branch 3 times, most recently from ba3801c to b0d9a7c Compare April 18, 2020 16:15
@Lucus16
Copy link
Contributor Author

Lucus16 commented Apr 18, 2020

I rebased and squashed this. I built gnat9 and ghdl-mcode once and gnat6 a few times and did not encounter failures. I've marked ghdl-llvm as broken for now. I think this is ready to be merged.

@sylv-io I'd appreciate it if you could take over and find someone to merge this. I don't have much energy left to spend on this. I'll be around for questions.

@sylv-io
Copy link
Contributor

sylv-io commented Apr 18, 2020

I rebased and squashed this. I built gnat9 and ghdl-mcode once and gnat6 a few times and did not encounter failures. I've marked ghdl-llvm as broken for now. I think this is ready to be merged.

@sylv-io I'd appreciate it if you could take over and find someone to merge this. I don't have much energy left to spend on this. I'll be around for questions.

great thx! it's understandable, that your tired of this.
I will do my best to find some folks, but I'm quite new here.

@veprbl veprbl removed their request for review April 18, 2020 17:34
@ghost ghost self-assigned this Apr 18, 2020
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to build gnat6 and gnat9 on a machine with very high core count. I have previously looked at the changes while rebasing. I also tried to implement the suggestion by @flokli to use a different bootstrap compiler, but it was not successful and I would like to postpone this improvement to a later PR.

If there are no new concerns I will merge this next week.

Staging automation moved this from WIP to Ready Apr 18, 2020
Copy link
Member

@vcunat vcunat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-checked the diff, builds on x86_64 (once), building and running a trivial hello-world program. Even ghdl-llvm built for me 🤷 On i686 all fails in gnat6 step already, but that doesn't seem interesting.

In any case I believe this should get merged in some form; to me it seems OK as-is.

@ghost
Copy link

ghost commented Apr 20, 2020

I just did a bunch of small changes:

  • update ghdl to 0.37
  • use pname
  • quote homepage urls
  • use https for homepage urls
  • marked ghdl-llvm as unbroken (I was able to build it)
  • change commit messages to fit contribution guidelines

@vcunat vcunat changed the title WIP init gnat at 9.1 gnat: init at 9 Apr 20, 2020
@ghost ghost merged commit b674ace into NixOS:staging Apr 20, 2020
Staging automation moved this from Ready to Done Apr 20, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Staging
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants