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 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 requested review from bendlas and bhipple May 7, 2020
@matthewbauer matthewbauer changed the base branch from master to staging May 7, 2020
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.
@bhipple
bhipple approved these changes May 8, 2020
Copy link
Contributor

bhipple left a comment

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"

This comment has been minimized.

Copy link
@bhipple

bhipple May 8, 2020

Contributor

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

matthewbauer commented May 8, 2020

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

@matthewbauer matthewbauer merged commit b57016c into NixOS:staging May 9, 2020
17 of 18 checks passed
17 of 18 checks passed
gcc, gcc.passthru.tests on x86_64-darwin
Details
gcc.passthru.tests on x86_64-darwin No attempt
Details
Evaluation Performance Report Evaluator Performance Report
Details
gcc, gcc.passthru.tests on aarch64-linux Success
Details
gcc, gcc.passthru.tests on x86_64-linux Success
Details
grahamcofborg-eval ^.^!
Details
grahamcofborg-eval-check-maintainers matching changed paths to changed attrs...
Details
grahamcofborg-eval-check-meta config.nix: checkMeta = true
Details
grahamcofborg-eval-darwin nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./pkgs/t
Details
grahamcofborg-eval-lib-tests nix-build --arg pkgs import ./. {} ./lib/tests/release.nix
Details
grahamcofborg-eval-nixos nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./nixos/
Details
grahamcofborg-eval-nixos-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./nixos/
Details
grahamcofborg-eval-nixos-options nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./nixos/
Details
grahamcofborg-eval-nixpkgs-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./pkgs/t
Details
grahamcofborg-eval-nixpkgs-tarball nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./pkgs/t
Details
grahamcofborg-eval-nixpkgs-unstable-jobset nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="fe19555"; rev="fe1955588a5a6715178070ad1164a115aa9de1e0"; } ./pkgs/t
Details
grahamcofborg-eval-package-list nix-env -qa --json --file .
Details
grahamcofborg-eval-package-list-no-aliases nix-env -qa --json --file . --arg config { allowAliases = false; }
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.