Skip to content

Commit 622fdfd

Browse files
committed
tools: run CI with shared libs on GHA
1 parent f7c2a7e commit 622fdfd

File tree

3 files changed

+181
-1
lines changed

3 files changed

+181
-1
lines changed

.github/workflows/test-shared.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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_PIN: 6a489c9482ca676ce23c0bcd7f2e1795383325fa
32+
33+
permissions:
34+
contents: read
35+
36+
jobs:
37+
build:
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
include:
42+
- runner: ubuntu-24.04
43+
system: x86_64-linux
44+
- runner: ubuntu-24.04-arm
45+
system: aarch64-linux
46+
- runner: macos-13
47+
system: x86_64-darwin
48+
- runner: macos-14
49+
system: aarch64-darwin
50+
name: '${{ matrix.system }}: with shared libraries'
51+
runs-on: ${{ matrix.runner }}
52+
steps:
53+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
54+
55+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
56+
with:
57+
extra_nix_config: sandbox = true
58+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
59+
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/${{ env.NIXPKGS_PIN }}.tar.gz
60+
61+
- name: Configure sccache
62+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
63+
# GHA by default restrict those variables to github-script, however we need sscache to access them.
64+
with:
65+
script: |
66+
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
67+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
68+
69+
- name: Build Node.js and run tests
70+
run: |
71+
nix-shell \
72+
--arg loadJSBuiltinsDynamically false \
73+
--arg ccache '(import <nixpkgs} {}).sscache' \
74+
--arg devTools '[]' \
75+
--arg benchmarkTools '[]' \
76+
--run '
77+
set -ex
78+
make build-ci -j4 V=1
79+
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9"
80+
'

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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
simdutf
18+
sqlite
19+
uvwasi
20+
zlib
21+
zstd
22+
;
23+
http-parser = pkgs.llhttp;
24+
},
25+
ccache ? pkgs.ccache,
26+
devTools ? [
27+
pkgs.curl
28+
pkgs.gh
29+
pkgs.git
30+
pkgs.jq
31+
(if (ncu-path == null) then [
32+
pkgs.node-core-utils
33+
] else [
34+
(pkgs.writeShellScriptBin "git-node" "exec \"${ncu-path}/bin/git-node.js\" \"$@\"")
35+
(pkgs.writeShellScriptBin "ncu-ci" "exec \"${ncu-path}/bin/ncu-ci.js\" \"$@\"")
36+
(pkgs.writeShellScriptBin "ncu-config" "exec \"${ncu-path}/bin/ncu-config.js\" \"$@\"")
37+
])
38+
],
39+
benchmarkTools ? [
40+
pkgs.R
41+
pkgs.rPackages.ggplot2
42+
pkgs.rPackages.plyr
43+
],
44+
extraConfigFlags ? [
45+
"--without-npm"
46+
"--debug-node"
47+
],
48+
}:
49+
50+
let
51+
useSharedICU = if builtins.isString shared-icu then shared-icu == "system" else shared-icu != null;
52+
useSharedAda = builtins.hasAttr "ada" sharedLibDeps;
53+
in
54+
pkgs.mkShell {
55+
inherit (pkgs.nodejs_latest) nativeBuildInputs;
56+
57+
TEST = if useSharedICU then "true" else "false";
58+
buildInputs = builtins.attrValues sharedLibDeps ++ pkgs.lib.optionals useSharedICU [ shared-icu ];
59+
60+
packages = [
61+
ccache
62+
] ++ devTools ++ benchmarkTools;
63+
64+
CC = "${pkgs.lib.getExe ccache} cc";
65+
CXX = "${pkgs.lib.getExe ccache} c++";
66+
CI_SKIP_TESTS="${
67+
pkgs.lib.concatStringsSep "," ([
68+
] ++ pkgs.lib.optionals useSharedAda [
69+
# Different versions of Ada affect the WPT tests
70+
"test-url"
71+
])
72+
}";
73+
DIFF_CMD = "code --wait --diff";
74+
CONFIG_FLAGS = builtins.toString ([
75+
"--ninja"
76+
(if shared-icu == null
77+
then "--without-intl"
78+
else "--with-intl=${if useSharedICU then "system" else shared-icu}-icu")
79+
] ++ extraConfigFlags ++ pkgs.lib.optionals loadJSBuiltinsDynamically [
80+
"--node-builtin-modules-path=${builtins.toString ./.}"
81+
] ++ pkgs.lib.concatMap (name: [
82+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}"
83+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}-libpath=${
84+
pkgs.lib.getLib sharedLibDeps.${name}
85+
}/lib"
86+
"--shared-${builtins.replaceStrings [ "c-ares" ] [ "cares" ] name}-include=${
87+
pkgs.lib.getInclude sharedLibDeps.${name}
88+
}/include"
89+
]) (builtins.attrNames sharedLibDeps));
90+
}

0 commit comments

Comments
 (0)