Skip to content

Commit df591de

Browse files
committed
feat: enable sccache for Darwin (aarch64-darwin) builds
Add sccache support for self-hosted Darwin runners by: 1. Mounting the sccache disk using stickydisk action 2. Configuring proper permissions for the sccache directory 3. Adding extra-sandbox-paths to Nix configuration to allow access This brings Darwin builds to parity with Linux builds in terms of sccache caching support.
1 parent 3f7cf28 commit df591de

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

.github/workflows/nix-build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,28 @@ jobs:
126126
- name: Checkout Repo
127127
if: ${{ matrix.attr != '' }}
128128
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
129+
- name: Mount sccache disk
130+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
131+
uses: useblacksmith/stickydisk@v1
132+
with:
133+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
134+
path: /nix/var/cache/sccache
129135
- name: Install nix
130136
if: ${{ matrix.attr != '' }}
131137
uses: ./.github/actions/nix-install-self-hosted
138+
- name: Configure sccache for Nix builds
139+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
140+
run: |
141+
# Ensure sccache directory is writable by the build user
142+
sudo mkdir -p /nix/var/cache/sccache
143+
sudo chown -R $(whoami) /nix/var/cache/sccache
144+
sudo chmod -R 755 /nix/var/cache/sccache
145+
146+
# Update Nix configuration to allow access to sccache directory in sandbox
147+
# Create temporary nix.conf with our additions
148+
sudo tee -a /etc/nix/nix.conf > /dev/null <<EOF
149+
extra-sandbox-paths = /nix/var/cache/sccache
150+
EOF
132151
- name: nix build
133152
if: ${{ matrix.attr != '' }}
134153
shell: bash
@@ -149,9 +168,28 @@ jobs:
149168
- name: Checkout Repo
150169
if: ${{ matrix.attr != '' }}
151170
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
171+
- name: Mount sccache disk
172+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
173+
uses: useblacksmith/stickydisk@v1
174+
with:
175+
key: ${{ github.repository }}-sccache-${{ runner.os }}-${{ runner.arch }}-${{ matrix.cache_key }}
176+
path: /nix/var/cache/sccache
152177
- name: Install nix
153178
if: ${{ matrix.attr != '' }}
154179
uses: ./.github/actions/nix-install-self-hosted
180+
- name: Configure sccache for Nix builds
181+
if: ${{ matrix.attr != '' && matrix.postgresql_version }}
182+
run: |
183+
# Ensure sccache directory is writable by the build user
184+
sudo mkdir -p /nix/var/cache/sccache
185+
sudo chown -R $(whoami) /nix/var/cache/sccache
186+
sudo chmod -R 755 /nix/var/cache/sccache
187+
188+
# Update Nix configuration to allow access to sccache directory in sandbox
189+
# Create temporary nix.conf with our additions
190+
sudo tee -a /etc/nix/nix.conf > /dev/null <<EOF
191+
extra-sandbox-paths = /nix/var/cache/sccache
192+
EOF
155193
- name: nix build
156194
if: ${{ matrix.attr != '' }}
157195
shell: bash

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ let
165165
buildPhase = ''
166166
runHook preBuild
167167
168-
168+
${lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
169169
if [[ -d "/nix/var/cache/sccache" && -w "/nix/var/cache/sccache" ]]; then
170170
echo "sccache: cache directory available, enabling"
171171
export RUSTC_WRAPPER="${sccache}/bin/sccache"
@@ -174,6 +174,7 @@ let
174174
else
175175
echo "sccache: cache directory not available, skipping"
176176
fi
177+
''}
177178
178179
echo "Executing cargo-pgrx buildPhase"
179180
${preBuildAndTest}
@@ -195,10 +196,12 @@ let
195196
--features "${builtins.concatStringsSep " " buildFeatures}" \
196197
--out-dir "$out"
197198
199+
${lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
198200
if [[ -n "''${RUSTC_WRAPPER:-}" ]]; then
199201
echo "sccache stats:"
200202
${sccache}/bin/sccache --show-stats
201203
fi
204+
''}
202205
203206
${maybeLeaveBuildAndTestSubdir}
204207

0 commit comments

Comments
 (0)