Skip to content

Commit c49f313

Browse files
committed
initial commit
0 parents  commit c49f313

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: build
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
build:
10+
name: build
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- name: build-image
15+
run: |
16+
pushd "$(mktemp -d)"
17+
curl -f -L --retry 5 https://github.com/tweag/rust-alpine-mimalloc/archive/refs/heads/master.tar.gz | tar xz --strip-components=1
18+
podman build \
19+
--network host \
20+
--pull \
21+
--squash \
22+
--tag rust:alpine-mimalloc \
23+
.
24+
popd
25+
26+
- name: checkout
27+
uses: actions/checkout@v4
28+
29+
- name: build-node
30+
run: |
31+
podman run \
32+
--init \
33+
--network host \
34+
--rm \
35+
--tmpfs /tmp:exec \
36+
--volume $PWD:/workspace \
37+
--workdir /workspace \
38+
rust:alpine-mimalloc \
39+
/workspace/build.sh
40+
41+
- name: upload-artifact
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: node-linux-x64-static
45+
path: node-v*-linux-x64-static.tar.xz

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# `node-static`
2+
3+
Highly opinionated x86_64-linux nodejs build, fully statically linked,
4+
with pointer compression, clang LTO and mimalloc. Should be fast
5+
when it works, but it doesn't work with native addons, so don't use it
6+
in your project unless you know what you're doing.

build.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
node_ver=21.2.0
6+
7+
apk add \
8+
clang \
9+
linux-headers \
10+
lld \
11+
llvm \
12+
python3 \
13+
xz
14+
15+
cd "$(mktemp -d)"
16+
17+
curl -f -L --retry 5 https://github.com/nodejs/node/archive/refs/tags/v$node_ver.tar.gz | tar xz --strip-components=1
18+
curl -f -L --retry 5 https://github.com/nodejs/node/commit/0ee49c8620793ec09bc9b8303a1915d289975fb3.diff | patch -p1
19+
curl -f -L --retry 5 https://github.com/nodejs/node/commit/09f4aa948918bb43a45a29d89515f568336b4531.diff | patch -p1
20+
curl -f -L --retry 5 https://github.com/nodejs/node/commit/ec023a7a793f2e2e457e811e4c6ab9e81d5feeb0.diff | patch -p1
21+
curl -f -L --retry 5 https://github.com/nodejs/node/commit/8e60189585dce0327eca38aef8e72ed5d58e7b6f.diff | patch -p1
22+
patch -p1 -i /workspace/node-clang-lto.diff
23+
24+
make -j"$(nproc)" binary \
25+
AR="llvm-ar" \
26+
CC="clang" \
27+
CXX="clang++" \
28+
CONFIG_FLAGS="--enable-lto --experimental-enable-pointer-compression --fully-static --openssl-use-def-ca-store" \
29+
VARIATION="static"
30+
31+
out/Release/node -e 'console.log(6*7)' | grep -F 42
32+
33+
mv node-v$node_ver-linux-x64-static.tar.xz /workspace

node-clang-lto.diff

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
diff --git a/common.gypi b/common.gypi
2+
index c51dbca5..1ebcc2c4 100644
3+
--- a/common.gypi
4+
+++ b/common.gypi
5+
@@ -176,7 +176,7 @@
6+
['llvm_version=="0.0"', {
7+
'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
8+
}, {
9+
- 'lto': ' -flto ', # Clang
10+
+ 'lto': ' -flto=thin ', # Clang
11+
}],
12+
],
13+
},
14+
@@ -184,7 +184,7 @@
15+
'conditions': [
16+
['enable_lto=="true"', {
17+
'cflags': ['<(lto)'],
18+
- 'ldflags': ['<(lto)'],
19+
+ 'ldflags': ['<(lto)', '-fuse-ld=lld', '-Wl,--strip-all,--thinlto-cache-dir=/tmp'],
20+
'xcode_settings': {
21+
'LLVM_LTO': 'YES',
22+
},
23+
diff --git a/deps/cares/configure b/deps/cares/configure
24+
index ebaa43c2..4f7861a8 100755
25+
--- a/deps/cares/configure
26+
+++ b/deps/cares/configure
27+
@@ -18815,11 +18815,6 @@ _LT_EOF
28+
29+
30+
_lt_libdeps_save_CFLAGS=$CFLAGS
31+
-case "$CC $CFLAGS " in #(
32+
-*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
33+
-*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
34+
-*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
35+
-esac
36+
37+
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
38+
(eval $ac_compile) 2>&5
39+
diff --git a/deps/cares/m4/libtool.m4 b/deps/cares/m4/libtool.m4
40+
index e7b68334..13ec17a6 100644
41+
--- a/deps/cares/m4/libtool.m4
42+
+++ b/deps/cares/m4/libtool.m4
43+
@@ -7562,11 +7562,6 @@ _LT_EOF
44+
])
45+
46+
_lt_libdeps_save_CFLAGS=$CFLAGS
47+
-case "$CC $CFLAGS " in #(
48+
-*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
49+
-*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
50+
-*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
51+
-esac
52+
53+
dnl Parse the compiler output and extract the necessary
54+
dnl objects, libraries and library flags.
55+
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
56+
index 45323919..3cf40c59 100644
57+
--- a/tools/v8_gypfiles/v8.gyp
58+
+++ b/tools/v8_gypfiles/v8.gyp
59+
@@ -1723,9 +1723,6 @@
60+
'<!@pymod_do_main(GN-scraper "<(V8_ROOT)/BUILD.gn" "v8_source_set.\\"v8_heap_base.*?sources = ")',
61+
],
62+
'conditions': [
63+
- ['enable_lto=="true"', {
64+
- 'cflags_cc': [ '-fno-lto' ],
65+
- }],
66+
['clang or OS!="win"', {
67+
'conditions': [
68+
['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', {

0 commit comments

Comments
 (0)