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

Share ccache among GitHub Action workflow runs #9246

Draft
wants to merge 106 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
76b93b5
Update flake.nix
Atry Oct 5, 2022
642f5d3
Manually pass isDefaultStdlib
Atry Oct 5, 2022
cefdec2
Add extra-sandbox-paths = /nix/var/cache/ccache
Atry Oct 5, 2022
c5ac987
Configure ccache
Atry Oct 5, 2022
054233a
Set CCACHE_DIR
Atry Oct 5, 2022
6164f1c
Fix nix syntax errors
Atry Oct 5, 2022
8deefcd
Add finalAttrs: previousAttrs:
Atry Oct 5, 2022
a20b0a6
Add ccache to devShells.default
Atry Oct 6, 2022
0312c69
Initialize ccache in Dockerfile
Atry Oct 6, 2022
e573f0e
Add sudo
Atry Oct 6, 2022
f91e0f5
Update flake.nix
Atry Oct 7, 2022
2f8faef
Update nix.yml
Atry Oct 7, 2022
24b2357
Update nix.yml
Atry Oct 7, 2022
a4cb668
Merge commit 'e86413bb91ae5f12193d0cedc382d6cefeff12cc' into Atry-pat…
Atry Oct 7, 2022
54e4b49
Update nix.yml
Atry Oct 7, 2022
fc179d2
Update nix.yml
Atry Oct 7, 2022
da45dc3
Update nix.yml
Atry Oct 7, 2022
f97f091
Update nix.yml
Atry Oct 7, 2022
526c3e2
Revert "Update nix.yml"
Atry Oct 7, 2022
b05e533
Workaround for https://github.com/actions/toolkit/issues/946
Atry Oct 7, 2022
3992a13
Increase CCACHE_MAXSIZE
Atry Oct 7, 2022
5c799c0
Merge commit 'f91e0f556885fb3f5661e56e3529ab14a55c99e2' into Atry-pat…
Atry Oct 7, 2022
de087e8
Merge commit '5c799c0290db805b6ba95a506112068f1100cdf4' into Atry-pat…
Atry Oct 7, 2022
935ba41
Switch to sccache
Atry Oct 11, 2022
73ad433
Switch to CMAKE_TOOLCHAIN_FILE
Atry Oct 11, 2022
799544c
Minor changes
Atry Oct 11, 2022
5ff585f
Merge commit '799544c2688440315d917a01ab253f1465bd9f49' into Atry-pat…
Atry Oct 11, 2022
f3d527a
Merge commit '3be508721660a55139ab0585399151eb395dc151' into Atry-pat…
Atry Oct 11, 2022
01a62fb
Remove ccache paths
Atry Oct 11, 2022
5586a47
Merge commit 'f1e006029a0aab4bf08cfc09b8878b3f6e545eb1' into Atry-pat…
Atry Oct 11, 2022
a11e077
Merge commit '01a62fb7dbcb808e690d6d9aadc21745ab35286f' into Atry-pat…
Atry Oct 11, 2022
1d604f0
hhvm_sccache
Atry Oct 11, 2022
f7fdaa0
Merge commit '1d604f031909e4b4718096f6169cf8955d5cdd92' into Atry-pat…
Atry Oct 11, 2022
f058d47
hhvm_sccache
Atry Oct 11, 2022
7de1770
Assume the AWS role
Atry Oct 11, 2022
92dff7f
Add --impure flag for hhvm_sccache
Atry Oct 11, 2022
68af563
Set up SCCACHE_BUCKET and SCCACHE_ENDPOINT
Atry Oct 11, 2022
9b61c41
Fix workflow grammar
Atry Oct 11, 2022
6bb8d27
Add port for SCCACHE_ENDPOINT
Atry Oct 12, 2022
a5ad2bf
Use SSL
Atry Oct 18, 2022
3dbb117
Merge commit '1f280df4fce3d5e9ea9df2aa9bfe508586dee9b9' into Atry-pat…
Atry Oct 20, 2022
e6472cb
Add default value for isDefaultStdlib
Atry Oct 20, 2022
1019f96
Use a patched sccache
Atry Oct 20, 2022
5091ddf
Merge commit '1019f96a5ef40f7e95c36037c2d929d47ac1fe97' into Atry-pat…
Atry Oct 20, 2022
cac68b8
Set up environment variables for patched sccache
Atry Oct 20, 2022
504f76f
Add metadata for sccache_pr1086
Atry Oct 20, 2022
651a49e
Always stop sccache server even if compilation fails
Atry Oct 20, 2022
d6966f7
Add sudo
Atry Oct 20, 2022
b0e1d54
Remove --group
Atry Oct 20, 2022
6a7f482
Use full path of nix
Atry Oct 20, 2022
5c89e56
Upload patched sccache to nix binary cache
Atry Oct 20, 2022
b980f6b
Fix meta data for patched sccache
Atry Oct 20, 2022
dded0b2
Use --impure flag to pass environment variables
Atry Oct 20, 2022
243152a
Always stop sccache server
Atry Oct 20, 2022
9f3392c
Remove hhvm_sccache package
Atry Oct 20, 2022
726bc1a
Always stop
Atry Oct 20, 2022
26d6e54
Revert "Always stop sccache server"
Atry Oct 20, 2022
6f5816d
Merge commit '8260557758dfe12058666963ce6bc7110f66e310' into Atry-pat…
Atry Oct 20, 2022
36e2626
Remove RUSTC_WRAPPER from dev shell
Atry Oct 20, 2022
314eca3
Revert isDefaultStdlib changes
Atry Oct 20, 2022
c1306c3
Rename CMAKE_INIT_CACHE to CMAKE_TOOLCHAIN_FILE
Atry Oct 20, 2022
1d88b8e
Remove hhvm_sccache package
Atry Oct 20, 2022
8f44b0e
Merge commit 'c1306c34088' into Atry-patch-20
Atry Oct 20, 2022
f4443e1
Revert "Rename CMAKE_INIT_CACHE to CMAKE_TOOLCHAIN_FILE"
Atry Oct 20, 2022
3baede2
Revert unrelated changes
Atry Oct 20, 2022
e2c8fdd
Add inheritedEnvironmentVariables
Atry Oct 20, 2022
c8811ed
Use nix build --print-out-paths instead of nix eval
Atry Oct 20, 2022
26b335a
Use nix build --print-out-paths instead of nix eval
Atry Oct 20, 2022
15e4290
Revert "Use nix build --print-out-paths instead of nix eval"
Atry Oct 20, 2022
15ab607
Remove debugging code
Atry Oct 20, 2022
1a9c405
Upload sccache binaries to the binary cache server on S3 earlier
Atry Oct 20, 2022
b478aab
Remove sccache --stop-server command
Atry Oct 20, 2022
4a53fa8
Update nix.yml
Atry Oct 21, 2022
b918336
Update nix.yml
Atry Oct 24, 2022
7d82b4c
Update nix.yml
Atry Oct 24, 2022
0c8d137
Merge commit 'b918336386ac19152e5836832909d175760d1f9c' into Atry-pat…
Atry Oct 24, 2022
180c76f
Pass compiler caching settings via shell script instead of derivation…
Atry Oct 24, 2022
f3c8d1c
Add more comments
Atry Oct 25, 2022
576bafc
Add version attribute for sccache_pr1086
Atry Oct 25, 2022
af451eb
Add log file for sccache
Atry Oct 25, 2022
498ba68
Merge commit 'f0ea5318c4bbba3b817901337a85d6d593bc6840' into Atry-pat…
Atry Oct 25, 2022
b2ccd74
Add if: always() for printing sccache logs
Atry Oct 25, 2022
63f0574
Set proper file permission for /nix/var/sccache
Atry Oct 25, 2022
5d5e15a
Add sudo to print sccache logs
Atry Oct 25, 2022
f29e22a
Merge commit 'cbfb7be22ea00f67cc576fd08056aea99b577ca2' into Atry-pat…
Atry Oct 25, 2022
aa446c5
Override unpackPhase
Atry Oct 25, 2022
8a8c323
Move sccache related attributes to flake.nix
Atry Oct 25, 2022
cd6712e
Fix pkgs.lib reference
Atry Oct 25, 2022
552f26f
Call eval unpackPhase
Atry Oct 25, 2022
707352c
Print CMakeCache.txt and stop sccache server
Atry Oct 25, 2022
e559894
Fix nix syntax
Atry Oct 25, 2022
1d4b2c9
Specify cmakeBuildDir
Atry Oct 25, 2022
530bb27
cat CMakeCache.txt
Atry Oct 25, 2022
57ede1d
Also print environment variables
Atry Oct 26, 2022
6d14b87
Add the missing dollar
Atry Oct 26, 2022
5f9b3d6
Override TEMPDIR
Atry Oct 26, 2022
bce39d7
Remove -a
Atry Oct 26, 2022
62be3d7
Add packages.hhvm_nocache
Atry Oct 26, 2022
c663a5c
Fix nix syntax
Atry Oct 26, 2022
6db20db
Set TMPDIR=/tmp
Atry Oct 26, 2022
6dfe4a8
Add comments
Atry Oct 26, 2022
0a0b50b
Add SCCACHE_IDLE_TIMEOUT=0
Atry Oct 26, 2022
49e2917
Update nix.yml
Atry Oct 27, 2022
0201671
Merge commit '49e2917b4ce975170849651ecf3920e0b108b903' into HEAD
Atry Oct 27, 2022
fec590c
Update nix.yml
Atry Oct 28, 2022
6b5ebba
Merge commit 'c8ee0b7fe09c2dfe01d297a97b8e057212f1f9cc' into Atry-pat…
Atry Oct 29, 2022
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
89 changes: 79 additions & 10 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,86 @@ 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=

# HHVM cannot be built in a sandbox for now because some CMake files
# are downloading files from internet, which is forbidden if
# sandboxing is enabled.
sandbox = false
- 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}}"

# extra-sandbox-paths does not take effect when sandbox = false, but
# we will need the setting if we build HHVM in a sandbox in the future
extra-sandbox-paths = /nix/var/sccache
- name: Build sccache and create a shell script to set up it
run: |
set -ex
SCCACHE_INSTALL_PATH="$(nix build --print-out-paths --no-link "git+file://$(pwd)?submodules=1&shallow=1#sccache_pr1086")"

sudo mkdir -m0770 -p /nix/var/sccache

printf \
'
# By default, nix will set TEMPDIR and TMPDIR to a unique directory
# among builds, preventing compiler cache.
# Set them to /tmp to allow for compiler cache.
export TEMPDIR=/tmp
export TMPDIR=/tmp

export SCCACHE_BUCKET="hhvm-sccache"
export SCCACHE_ENDPOINT="https://hhvm-sccache.s3-accelerate.amazonaws.com"
export SCCACHE_REGION="us-west-2"

# Do not shut down sccache server automatically because we will
# manually shut down sccache server to print statistics.
export SCCACHE_IDLE_TIMEOUT=0

export SCCACHE_ERROR_LOG=/nix/var/sccache/sccache_log.txt
export SCCACHE_LOG=debug

export RUSTC_WRAPPER=%q/bin/sccache
export CMAKE_C_COMPILER_LAUNCHER="$RUSTC_WRAPPER"
export CMAKE_CXX_COMPILER_LAUNCHER="$RUSTC_WRAPPER"
' \
"$SCCACHE_INSTALL_PATH" |
sudo tee /nix/var/sccache/setup-compiler-cache.sh

# Assign the owner for the generated shell script, because it will be
# used by the nix builder users. See https://nixos.wiki/wiki/CCache
sudo chown -R --reference=/nix/store /nix/var/sccache
- name: Assume the AWS role
continue-on-error: true
id: configure-aws-credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::223121549624:role/hhvm-github-actions
# 6 hours
role-duration-seconds: 21600
aws-region: us-west-2
- name: Sign sccache binaries with a private key downloaded from AWS Secrets Manager
if: steps.configure-aws-credentials.outcome == 'success'
run: nix store sign --recursive --key-file <(aws secretsmanager get-secret-value --secret-id hhvm-nix-cache-1 --query SecretString --output text) --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#sccache_pr1086"
- name: Upload sccache binaries to the binary cache server on S3
if: steps.configure-aws-credentials.outcome == 'success'
run: nix copy --to 's3://hhvm-nix-cache?region=us-west-2&endpoint=hhvm-nix-cache.s3-accelerate.amazonaws.com' --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#sccache_pr1086"
- name: Set up sccache for read-only caching on AWS S3
if: steps.configure-aws-credentials.outcome != 'success'
run: |
sudo tee -a /nix/var/sccache/setup-compiler-cache.sh <<EOF
export SCCACHE_S3_NO_CREDENTIALS=1
EOF
- name: Set up sccache for read/write caching on AWS S3
if: steps.configure-aws-credentials.outcome == 'success'
run: |
printf '
export AWS_ACCESS_KEY_ID=%q
export AWS_SECRET_ACCESS_KEY=%q
export AWS_SESSION_TOKEN=%q
' "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "$AWS_SESSION_TOKEN" |
sudo tee -a /nix/var/sccache/setup-compiler-cache.sh
- name: Build and install HHVM
run: nix profile install --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#${{matrix.package}}"
- if: always()
name: Print sccache logs
run: sudo cat /nix/var/sccache/sccache_log.txt
- run: hhvm --version
- name: Build the deb package
if: runner.os == 'Linux'
Expand Down Expand Up @@ -80,14 +157,6 @@ jobs:
with:
name: ${{matrix.package}}.rpm
path: ${{matrix.package}}.rpm
- name: Assume the AWS role
continue-on-error: true
id: configure-aws-credentials
if: github.event_name != 'pull_request'
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::223121549624:role/hhvm-github-actions
aws-region: us-west-2
- name: Sign Nix binaries with a private key downloaded from AWS Secrets Manager
if: steps.configure-aws-credentials.outcome == 'success'
run: nix store sign --recursive --key-file <(aws secretsmanager get-secret-value --secret-id hhvm-nix-cache-1 --query SecretString --output text) --print-build-logs "git+file://$(pwd)?submodules=1&shallow=1#${{matrix.package}}"
Expand Down
65 changes: 64 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,74 @@
NIX_CFLAGS_COMPILE
CMAKE_TOOLCHAIN_FILE;
};
setupCompilerCache = "/nix/var/sccache/setup-compiler-cache.sh";
in
rec {
packages.hhvm = pkgs.callPackage ./hhvm.nix {
packages.sccache_pr1086 = pkgs.sccache.overrideAttrs (finalAttrs: previousAttrs: rec {
version = "pr1086";
src = pkgs.fetchFromGitHub {
owner = "alessandrod";
repo = "sccache";
rev = "new-s3";
sha256 = "sha256-ExVVFLfQH/Tr++UgtT9fHs+tM0yOp5pIWO0rKTubNFs=";
};
cargoDeps = previousAttrs.cargoDeps.overrideAttrs (_: {
inherit src;
outputHash = "sha256-2eahz8z/nBmBM6L6OnrdjLALnVXESMe8cMOGszF22I8=";
});
meta = previousAttrs.meta // {
description = "Patched sccache with working S3 support";
homepage = "https://github.com/mozilla/sccache/pull/1086";
};
});

packages.hhvm_nocache = pkgs.callPackage ./hhvm.nix {
inherit setupCompilerCache;
lastModifiedDate = self.lastModifiedDate;
};

packages.hhvm = packages.hhvm_nocache.overrideAttrs(finalAttrs: previousAttrs: {
# Override unpackPhase to create a fixed sourceRoot so that the path
# can be cached by sccache
unpackPhase = ''
if [[ -f ${pkgs.lib.strings.escapeShellArg setupCompilerCache} ]]
then
runHook preUnpack
sourceRoot=/tmp/hhvm-cmake-build
cp -pr --reflink=auto -- "$src" "$sourceRoot"
cd "$sourceRoot"
echo "source root is $sourceRoot"
chmod -R u+w -- "$sourceRoot"
runHook postUnpack
else
# The default unpackPhase function, which copies sources to
# a directory whose name is different between builds
eval unpackPhase
fi
'';

# We pass compiler cache settings as a shell script specified by
# `setupCompilerCache`, not as derivation attributes, because we don't want
# to change the derivation hash changes due to different AWS_SESSION_TOKEN
# values.
preConfigure = ''
if [[ -f ${pkgs.lib.strings.escapeShellArg setupCompilerCache} ]]
then
. ${pkgs.lib.strings.escapeShellArg setupCompilerCache}
fi
'';

postConfigure = ''
set -x
cat CMakeCache.txt
env
set +x
'';

postBuild = ''
"$RUSTC_WRAPPER" --stop-server
'';
});
packages.hhvm_clang = packages.hhvm.override {
stdenv = pkgs.llvmPackages_14.stdenv;
};
Expand Down
1 change: 1 addition & 0 deletions hhvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
, re2
, re2c
, rustChannelOf
, setupCompilerCache
, stdenv
, sqlite
, tbb
Expand Down