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

Use ccache in the default devShell #9238

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
FROM ghcr.io/xtruder/nix-devcontainer:v1
RUN echo 'extra-sandbox-paths = /nix/var/cache/ccache' | sudo tee -a /etc/nix/nix.conf
RUN sudo mkdir -m0770 -p /nix/var/cache/ccache
RUN sudo chown --reference=/nix/store /nix/var/cache/ccache
5 changes: 5 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ jobs:
extra-substituters = s3://hhvm-nix-cache?region=us-west-2&endpoint=hhvm-nix-cache.s3-accelerate.amazonaws.com
extra-trusted-substituters = s3://hhvm-nix-cache?region=us-west-2&endpoint=hhvm-nix-cache.s3-accelerate.amazonaws.com
extra-trusted-public-keys = hhvm-nix-cache-1:MvKxscw16fAq6835oG8sbRgTGITb+1xGfYNhs+ee4yo=
extra-sandbox-paths = /nix/var/cache/ccache
sandbox = false
- run: |
# See https://nixos.wiki/wiki/CCache
sudo mkdir -m0770 -p /nix/var/cache/ccache
sudo chown --reference=/nix/store /nix/var/cache/ccache
- run: nix build --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#${{matrix.package}}"
- run: nix profile install --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#${{matrix.package}}"
- run: hhvm --version
Expand Down
4 changes: 0 additions & 4 deletions clang.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
]
}
},
"cmake.configureArgs": [
"-C",
"${env:CMAKE_INIT_CACHE}"
],
"cmake.buildDirectory": "${workspaceFolder}/_build"
},
"extensions": {
Expand Down
18 changes: 16 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,34 @@
];
inherit (hhvm)
NIX_CFLAGS_COMPILE
CMAKE_INIT_CACHE;
CMAKE_TOOLCHAIN_FILE;
${if hhvm?RUSTC_WRAPPER then "RUSTC_WRAPPER" else null} =
hhvm.RUSTC_WRAPPER;
};
in
rec {
packages.hhvm = pkgs.callPackage ./hhvm.nix {
lastModifiedDate = self.lastModifiedDate;
isDefaultStdlib = true;
};
packages.hhvm_ccache = packages.hhvm.overrideAttrs (finalAttrs: previousAttrs: {
RUSTC_WRAPPER = "${pkgs.sccache}/bin/sccache";
CMAKE_TOOLCHAIN_FILE = pkgs.writeTextFile {
name = "toolchain.cmake";
text = ''
${builtins.readFile packages.hhvm.CMAKE_TOOLCHAIN_FILE}
set(CMAKE_C_COMPILER_LAUNCHER "${pkgs.sccache}/bin/sccache" CACHE STRING "C compiler launcher" FORCE)
set(CMAKE_CXX_COMPILER_LAUNCHER "${pkgs.sccache}/bin/sccache" CACHE STRING "C++ compiler launcher" FORCE)
'';
};
});
packages.hhvm_clang = packages.hhvm.override {
stdenv = pkgs.llvmPackages_14.stdenv;
};
packages.default = packages.hhvm;

devShells.clang = devShellForPackage packages.hhvm_clang;
devShells.default = devShellForPackage packages.hhvm;
devShells.default = devShellForPackage packages.hhvm_ccache;

${if pkgs.hostPlatform.isLinux then "bundlers" else null} =
let
Expand Down
4 changes: 0 additions & 4 deletions hhvm.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"path": "nix-shell"
}
},
"cmake.configureArgs": [
"-C",
"${env:CMAKE_INIT_CACHE}"
],
"cmake.buildDirectory": "${workspaceFolder}/_build"
},
"extensions": {
Expand Down
12 changes: 5 additions & 7 deletions hhvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
, gperftools
, hostPlatform
, icu
# TODO(https://github.com/NixOS/nixpkgs/pull/193086): Use stdenv.cc.libcxx to
# detect C++ runtime once it is available
, isDefaultStdlib
, imagemagick6
, jemalloc
, lastModifiedDate
Expand Down Expand Up @@ -70,9 +73,6 @@
, zstd
}:
let
# TODO(https://github.com/NixOS/nixpkgs/pull/193086): Use stdenv.cc.libcxx once it is available
isDefaultStdlib =
builtins.match ".*-stdlib=\+\+.*" (builtins.readFile "${stdenv.cc}/nix-support/libcxx-ldflags") == null;
versionParts =
builtins.match
''
Expand Down Expand Up @@ -214,8 +214,8 @@ stdenv.mkDerivation rec {
"-Wno-error=unused-command-line-argument"
];

CMAKE_INIT_CACHE = writeTextFile {
name = "init-cache.cmake";
CMAKE_TOOLCHAIN_FILE = writeTextFile {
name = "toolchain.cmake";
text = ''
set(ENABLE_SYSTEM_LOCALE_ARCHIVE ON CACHE BOOL "Use system locale archive as the default LOCALE_ARCHIVE for nix patched glibc" FORCE)
set(CAN_USE_SYSTEM_ZSTD ON CACHE BOOL "Use system zstd" FORCE)
Expand All @@ -232,8 +232,6 @@ stdenv.mkDerivation rec {
'';
};

cmakeFlags = [ "-C" CMAKE_INIT_CACHE ];

prePatch = ''
patchShebangs .
'';
Expand Down