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

Add libgccjit #87157

Merged
merged 2 commits into from May 9, 2020
Merged

Add libgccjit #87157

merged 2 commits into from May 9, 2020

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented May 7, 2020

libgccjit is a special "language" frontend of gcc which can compile programs. It can be embedded and used as a library, similar to llvm.

This can be used to build gccemacs. For instance:

{ pkgs ? import <nixpkgs> {} }:
(pkgs.emacs.override { stdenv = pkgs.gcc9Stdenv; srcRepo = true; }).overrideAttrs (o: {
    src = pkgs.fetchgit {
      url = "https://git.savannah.gnu.org/git/emacs.git";
      rev = "766f4b96ee148adf8f4bbbf5fa4f1c47555d46de";
      sha256 = "sha256-3SJ431AsdurrDESo8HLElGhUzl0eyADIlit/PNV2FR4=";
    };
    LIBRARY_PATH = "${pkgs.lib.getLib pkgs.stdenv.cc.libc}/lib";
    patches = [];
    buildInputs = o.buildInputs or [] ++ [ pkgs.libgccjit ];
    makeFlags = o.makeFlags or [] ++ ["NATIVE_FAST_BOOT=1"];
    configureFlags = o.configureFlags or [] ++ ["--with-nativecomp"];
  })

which can be built with nix-build.

libgccjit is a library but is used as a compiler. So it references a
bunch of compiler things in $out. To avoid a cycle, we need to put
everything in $out, so referenced to $lib need to be replaced with
${!outputLib}.
@matthewbauer matthewbauer changed the base branch from master to staging May 7, 2020 02:54
This option can be used to set the “jit” language which enable the
libgccjit functionality. Also adds a “libgccjit” attr which is gcc
built with just jit enabled.
Copy link
Contributor

@bhipple bhipple left a comment

Choose a reason for hiding this comment

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

This is fantastic! I've managed to compile a gccemacs locally now, starting to play with it a bit.

Why do we need this line, though? It'd be nice if we could remove that bit, but doing so results in a broken jitter, similar to what I was seeing in my earlier efforts.

LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";


substituteInPlace libgfortran/configure \
--replace "-install_name \\\$rpath/\\\$soname" "-install_name $lib/lib/\\\$soname"
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, this trick of using ${!outputLib} to do indirect bash referencing to the output lib var that may either exist or just forward to $out was the trick I was missing when I was hacking at this. Pretty neat!

@matthewbauer
Copy link
Member Author

Why do we need this line, though? It'd be nice if we could remove that bit, but doing so results in a broken jitter, similar to what I was seeing in my earlier efforts.

LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";

libgccjit needs to know where libc & other runtime libs are. Normally we do this by inserting the flags through cc-wrapper's gcc. But libgccjit doesn't invoke gcc at all, so we need another way to do this. We could get rid of it if we could somehow wrap the library and setting that environment variable, but that's not quite possible in the same way we can do in a binary. This is basically the same situation as libclang is in: see #43366.

@bhipple
Copy link
Contributor

bhipple commented May 9, 2020

I now have a working gccemacs that I've used to stress test libgccjit and all appears to be well so far!

Since this is a no-op cleanup on regular stdenv and just adds the new pkg, I think this is ready to be merged, but I'll defer to @FRidh and/or @jonringer if there's a good time to start Hydra churning away rebuilding-the-world on staging again.

Resolves #75288

@collares
Copy link
Member

collares commented Jan 18, 2021

Thanks for this PR! Is there any reason libgccjit was pinned to gcc9, or was it just the current version at the time?

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

Successfully merging this pull request may close these issues.

None yet

3 participants