Skip to content

Commit dabb4c7

Browse files
committed
tools: run CI with shared libs on GHA
1 parent abccbb4 commit dabb4c7

File tree

5 files changed

+243
-1
lines changed

5 files changed

+243
-1
lines changed

.github/workflows/test-shared.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Test Shared librairies
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- .mailmap
7+
- README.md
8+
- .github/**
9+
- '!.github/workflows/test-shared.yml'
10+
types: [opened, synchronize, reopened, ready_for_review]
11+
push:
12+
branches:
13+
- main
14+
- canary
15+
- v[0-9]+.x-staging
16+
- v[0-9]+.x
17+
paths-ignore:
18+
- .mailmap
19+
- README.md
20+
- .github/**
21+
- '!.github/workflows/test-shared.yml'
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
25+
cancel-in-progress: true
26+
27+
env:
28+
PYTHON_VERSION: '3.12'
29+
FLAKY_TESTS: keep_retrying
30+
SCCACHE_GHA_ENABLED: 'true'
31+
NIXPKGS_REPO: https://github.com/NixOS/nixpkgs
32+
NIXPKGS_PIN: 6a489c9482ca676ce23c0bcd7f2e1795383325fa
33+
34+
permissions:
35+
contents: read
36+
37+
jobs:
38+
build:
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
include:
43+
- runner: ubuntu-24.04
44+
system: x86_64-linux
45+
- runner: ubuntu-24.04-arm
46+
system: aarch64-linux
47+
- runner: macos-13
48+
system: x86_64-darwin
49+
- runner: macos-14
50+
system: aarch64-darwin
51+
name: '${{ matrix.system }}: with shared libraries'
52+
runs-on: ${{ matrix.runner }}
53+
steps:
54+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
55+
56+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
57+
with:
58+
extra_nix_config: sandbox = true
59+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
60+
nix_path: nixpkgs=${{ env.NIXPKGS_REPO }}/archive/${{ env.NIXPKGS_PIN }}.tar.gz
61+
62+
- name: Configure sccache
63+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
64+
# GHA by default restrict those variables to github-script, however we need sscache to access them.
65+
with:
66+
script: |
67+
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
68+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
69+
70+
- name: Build Node.js and run tests
71+
run: |
72+
nix-shell \
73+
--arg loadJSBuiltinsDynamically false \
74+
--arg ccache '(import <nixpkgs> {}).sccache' \
75+
--arg devTools '[]' \
76+
--arg benchmarkTools '[]' \
77+
--run '
78+
set -ex
79+
make build-ci -j4 V=1
80+
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9"
81+
'

.github/workflows/tools.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030
- llhttp
3131
- minimatch
3232
- nbytes
33+
- nixpkgs-unstable
3334
- nghttp2
3435
- nghttp3
3536
- ngtcp2
@@ -198,6 +199,14 @@ jobs:
198199
cat temp-output
199200
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
200201
rm temp-output
202+
- id: nixpkgs-unstable
203+
subsystem: tools
204+
label: tools
205+
run: |
206+
./tools/dep_updaters/update-nixpkgs-pin.sh > temp-output
207+
cat temp-output
208+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
209+
rm temp-output
201210
- id: nghttp2
202211
subsystem: deps
203212
label: dependencies

BUILDING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Consult previous versions of this document for older versions of Node.js:
239239

240240
Installation via Linux package manager can be achieved with:
241241

242+
* Nix, NixOS: `nix-shell`
242243
* Ubuntu, Debian: `sudo apt-get install python3 g++-12 gcc-12 make python3-pip`
243244
* Fedora: `sudo dnf install python3 gcc-c++ make python3-pip`
244245
* CentOS and RHEL: `sudo yum install python3 gcc-c++ make python3-pip`
@@ -259,6 +260,16 @@ installed, you can find them under the menu `Xcode -> Open Developer Tool ->
259260
More Developer Tools...`. This step will install `clang`, `clang++`, and
260261
`make`.
261262

263+
#### Nix integration
264+
265+
If you are using Nix and direnv, you can use the following to get started:
266+
267+
```
268+
echo 'use_nix --attr sharedLibDeps {}' > .envrc
269+
direnv allow .
270+
make build-ci -j12
271+
```
272+
262273
#### Building Node.js
263274

264275
If the path to your build directory contains a space, the build will likely
@@ -267,7 +278,6 @@ fail.
267278
To build Node.js:
268279

269280
```bash
270-
export CXX=g++-12
271281
./configure
272282
make -j4
273283
```

shell.nix

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
pkgs ? import <nixpkgs> {},
3+
loadJSBuiltinsDynamically ? true, # Load `lib/**.js` from disk instead of embedding
4+
ncu-path ? null, # Provide this if you want to use a local version of NCU
5+
shared-icu ? pkgs.icu,
6+
sharedLibDeps ? {
7+
inherit (pkgs)
8+
ada
9+
brotli
10+
c-ares
11+
libuv
12+
nghttp2
13+
nghttp3
14+
ngtcp2
15+
openssl
16+
simdjson
17+
sqlite
18+
zlib
19+
zstd
20+
;
21+
http-parser = pkgs.llhttp;
22+
simdutf = pkgs.simdutf.overrideAttrs {
23+
version = "6.5.0";
24+
25+
src = pkgs.fetchFromGitHub {
26+
owner = "simdutf";
27+
repo = "simdutf";
28+
rev = "v6.5.0";
29+
hash = "sha256-bZ4r62GMz2Dkd3fKTJhelitaA8jUBaDjG6jOysEg8Nk=";
30+
};
31+
};
32+
},
33+
ccache ? pkgs.ccache,
34+
ninja ? pkgs.ninja,
35+
devTools ? [
36+
pkgs.curl
37+
pkgs.gh
38+
pkgs.git
39+
pkgs.jq
40+
pkgs.shellcheck
41+
] ++ (if (ncu-path == null) then [
42+
pkgs.node-core-utils
43+
] else [
44+
(pkgs.writeShellScriptBin "git-node" "exec \"${ncu-path}/bin/git-node.js\" \"$@\"")
45+
(pkgs.writeShellScriptBin "ncu-ci" "exec \"${ncu-path}/bin/ncu-ci.js\" \"$@\"")
46+
(pkgs.writeShellScriptBin "ncu-config" "exec \"${ncu-path}/bin/ncu-config.js\" \"$@\"")
47+
]),
48+
benchmarkTools ? [
49+
pkgs.R
50+
pkgs.rPackages.ggplot2
51+
pkgs.rPackages.plyr
52+
],
53+
extraConfigFlags ? [
54+
"--without-npm"
55+
"--debug-node"
56+
],
57+
}:
58+
59+
let
60+
useSharedICU = if builtins.isString shared-icu then shared-icu == "system" else shared-icu != null;
61+
useSharedAda = builtins.hasAttr "ada" sharedLibDeps;
62+
useSharedOpenSSL = builtins.hasAttr "openssl" sharedLibDeps;
63+
in
64+
pkgs.mkShell {
65+
inherit (pkgs.nodejs_latest) nativeBuildInputs;
66+
67+
buildInputs = builtins.attrValues sharedLibDeps ++ pkgs.lib.optionals useSharedICU [ shared-icu ];
68+
69+
packages = [
70+
ccache
71+
] ++ devTools ++ benchmarkTools;
72+
73+
shellHook = if (ccache != null) then ''
74+
export CC="${pkgs.lib.getExe ccache} $CC"
75+
export CXX="${pkgs.lib.getExe ccache} $CXX"
76+
'' else "";
77+
78+
BUILD_WITH = if (ninja != null) then "ninja" else "make";
79+
NINJA = if (ninja != null) then "${pkgs.lib.getExe ninja}" else "";
80+
CI_SKIP_TESTS="${
81+
pkgs.lib.concatStringsSep "," ([
82+
] ++ pkgs.lib.optionals useSharedAda [
83+
# Different versions of Ada affect the WPT tests
84+
"test-url"
85+
])
86+
}";
87+
CONFIG_FLAGS = builtins.toString ([
88+
(if shared-icu == null
89+
then "--without-intl"
90+
else "--with-intl=${if useSharedICU then "system" else shared-icu}-icu")
91+
] ++ extraConfigFlags ++ pkgs.lib.optionals (ninja != null) [
92+
"--ninja"
93+
] ++ pkgs.lib.optionals useSharedOpenSSL [
94+
"--openssl-use-def-ca-store"
95+
] ++ pkgs.lib.optionals loadJSBuiltinsDynamically [
96+
"--node-builtin-modules-path=${builtins.toString ./.}"
97+
] ++ pkgs.lib.concatMap (name: [
98+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}"
99+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}-libpath=${
100+
pkgs.lib.getLib sharedLibDeps.${name}
101+
}/lib"
102+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}-include=${
103+
pkgs.lib.getInclude sharedLibDeps.${name}
104+
}/include"
105+
]) (builtins.attrNames sharedLibDeps));
106+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
set -ex
3+
# Shell script to update Nixpkgs pin in the source tree to the most recent
4+
# version on the unstable channel.
5+
6+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
7+
WORKFLOW_FILE="$BASE_DIR/.github/workflows/test-shared.yml"
8+
9+
NIXPKGS_REPO=$(grep NIXPKGS_REPO: "$WORKFLOW_FILE" | awk -F': ' '{ print $2 }')
10+
CURRENT_VERSION_SHA1=$(grep NIXPKGS_PIN: "$WORKFLOW_FILE" | awk -F': ' '{ print $2 }')
11+
CURRENT_VERSION=$(echo "$CURRENT_UPSTREAM_SHA1" | head -c 7)
12+
13+
NEW_UPSTREAM_SHA1=$(git ls-remote "$NIXPKGS_REPO.git" nixpkgs-unstable | awk '{print $1}')
14+
NEW_VERSION=$(echo "$NEW_UPSTREAM_SHA1" | head -c 7)
15+
16+
17+
# shellcheck disable=SC1091
18+
. "$BASE_DIR/tools/dep_updaters/utils.sh"
19+
20+
compare_dependency_version "nixpkgs-unstable" "$NEW_VERSION" "$CURRENT_VERSION"
21+
22+
TMP_FILE=$(mktemp)
23+
sed "s/$CURRENT_VERSION_SHA1/$NEW_UPSTREAM_SHA1/" "$WORKFLOW_FILE" > "$TMP_FILE"
24+
mv "$TMP_FILE" "$WORKFLOW_FILE"
25+
26+
echo "All done!"
27+
echo ""
28+
echo "Please git add and commit the new version:"
29+
echo ""
30+
echo "$ git add $WORKFLOW_FILE"
31+
echo "$ git commit -m 'tools: bump nixpkgs-unstable pin to $NEW_VERSION'"
32+
echo ""
33+
34+
# The last line of the script should always print the new version,
35+
# as we need to add it to $GITHUB_ENV variable.
36+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)