Skip to content

Commit c0524c4

Browse files
Initial patch for fibers support
1 parent def0bdf commit c0524c4

15 files changed

Lines changed: 468 additions & 34 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build node-fibers with prebuilt Node
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- v24.13.0
8+
9+
jobs:
10+
build-fibers:
11+
strategy:
12+
matrix:
13+
include:
14+
- platform: linux
15+
arch: x64
16+
runs_on: ubuntu-22.04
17+
- platform: linux
18+
arch: arm64
19+
runs_on: ubuntu-22.04-arm
20+
runs-on: ${{ matrix.runs_on }}
21+
22+
env:
23+
NODE_VERSION: v24.13.0
24+
25+
steps:
26+
- name: Debug Matrix Values
27+
run: |
28+
echo "Matrix platform: ${{ matrix.platform }}"
29+
echo "Matrix arch: ${{ matrix.arch }}"
30+
31+
- name: Download Node archive
32+
run: |
33+
gh release download node-${{ env.NODE_VERSION }}-release \
34+
--repo asana/node \
35+
--pattern "node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz"
36+
mv node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz node.tar.xz
37+
pwd
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Download Dockerfile from GitHub API
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
curl -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw" -o Dockerfile.Fibers https://api.github.com/repos/Asana/node/contents/Dockerfile.Fibers?ref=v24.13.0
46+
cat Dockerfile.Fibers
47+
pwd
48+
49+
- name: Execute the Dockerfile
50+
run: |
51+
pwd
52+
docker build -t node24_fibers_build -f Dockerfile.Fibers .
53+
54+
- name: Extract resources
55+
run: |
56+
docker create --name temp_node_fibers_extract node24_fibers_build
57+
docker cp temp_node_fibers_extract:/usr/src/node/node-fibers $GITHUB_WORKSPACE/node-fibers
58+
docker rm temp_node_fibers_extract
59+
60+
- name: Find and archive fibers.node
61+
run: |
62+
# Find the directory under bin/ that contains fibers.node
63+
FIBERS_PATH=$(find ./node-fibers/bin -type f -name fibers.node | head -n1)
64+
FIBERS_DIR=$(dirname "$FIBERS_PATH")
65+
ARCHIVE_NAME=$(basename "$FIBERS_DIR").tar.gz
66+
echo "ARCHIVE_NAME=$ARCHIVE_NAME" >> $GITHUB_ENV
67+
tar -czf "$ARCHIVE_NAME" -C "$(dirname "$FIBERS_DIR")" "$(basename "$FIBERS_DIR")"
68+
69+
- name: Upload archive to release
70+
uses: softprops/action-gh-release@v1
71+
with:
72+
name: node-${{ env.NODE_VERSION }}-LATEST
73+
tag_name: node-${{ env.NODE_VERSION }}-release
74+
files: ${{ env.ARCHIVE_NAME }}
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build node-packages with prebuilt Node
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- v24.13.0
8+
9+
jobs:
10+
build-packages:
11+
strategy:
12+
matrix:
13+
include:
14+
- platform: linux
15+
arch: x64
16+
runs_on: ubuntu-22.04
17+
- platform: linux
18+
arch: arm64
19+
runs_on: ubuntu-22.04-arm
20+
runs-on: ${{ matrix.runs_on }}
21+
22+
env:
23+
NODE_VERSION: v24.13.0
24+
25+
steps:
26+
- name: Debug Matrix Values
27+
run: |
28+
echo "Matrix platform: ${{ matrix.platform }}"
29+
echo "Matrix arch: ${{ matrix.arch }}"
30+
31+
- name: Download Node archive
32+
run: |
33+
gh release download node-${{ env.NODE_VERSION }}-release \
34+
--repo asana/node \
35+
--pattern "node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz"
36+
mv node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz node.tar.xz
37+
pwd
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Download Dockerfile from GitHub API
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
curl -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw" -o Dockerfile.Packages https://api.github.com/repos/Asana/node/contents/Dockerfile.Packages?ref=v24.13.0
46+
cat Dockerfile.Packages
47+
pwd
48+
49+
- name: Execute the Dockerfile
50+
run: |
51+
pwd
52+
docker build -t node24_packages_build -f Dockerfile.Packages .
53+
54+
- name: Extract resources
55+
run: |
56+
docker create --name temp_node_packages_extract node24_packages_build
57+
docker cp temp_node_packages_extract:/usr/src/node/node_modules $GITHUB_WORKSPACE/node_modules
58+
docker rm temp_node_packages_extract
59+
60+
- name: Tar node-packages
61+
run: |
62+
mkdir -p ./bcrypt@5.1.0/node_modules
63+
mkdir -p ./cld@2.9.1/node_modules
64+
mkdir -p ./unix-dgram@2.0.6/node_modules
65+
mv node_modules/bcrypt ./bcrypt@5.1.0/node_modules/
66+
mv node_modules/cld ./cld@2.9.1/node_modules/
67+
mv node_modules/unix-dgram ./unix-dgram@2.0.6/node_modules/
68+
tar --hard-dereference -cvzf packages_${{matrix.arch}}.tar.gz bcrypt@5.1.0 cld@2.9.1 unix-dgram@2.0.6
69+
70+
- name: Upload archive to release
71+
uses: softprops/action-gh-release@v1
72+
with:
73+
name: node-${{ env.NODE_VERSION }}-LATEST
74+
tag_name: node-${{ env.NODE_VERSION }}-release
75+
files: packages_${{matrix.arch}}.tar.gz
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build-node.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Build Node
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- v24.13.0
8+
9+
jobs:
10+
build-node:
11+
name: Build ${{ matrix.platform }}-${{ matrix.arch }}
12+
strategy:
13+
matrix:
14+
include:
15+
- platform: linux
16+
arch: x64
17+
runs_on: ubuntu-22.04
18+
- platform: linux
19+
arch: arm64
20+
runs_on: ubuntu-22.04-arm
21+
runs-on: ${{ matrix.runs_on }}
22+
23+
env:
24+
S3_BUCKET: your-bucket-name
25+
AWS_REGION: us-east-1
26+
27+
steps:
28+
- name: Checkout Node fork
29+
uses: actions/checkout@v3
30+
with:
31+
repository: Asana/node
32+
path: node
33+
ref: ${{ github.event_name == 'pull_request' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.ref_name }}
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract Node Version
37+
id: extract-node-version
38+
run: |
39+
NODE_MAJOR_VERSION=$(grep '#define NODE_MAJOR_VERSION' node/src/node_version.h | awk '{print $3}')
40+
NODE_MINOR_VERSION=$(grep '#define NODE_MINOR_VERSION' node/src/node_version.h | awk '{print $3}')
41+
NODE_PATCH_VERSION=$(grep '#define NODE_PATCH_VERSION' node/src/node_version.h | awk '{print $3}')
42+
NODE_VERSION="v${NODE_MAJOR_VERSION}.${NODE_MINOR_VERSION}.${NODE_PATCH_VERSION}"
43+
echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV
44+
45+
- name: Set build metadata
46+
id: meta
47+
working-directory: node
48+
run: |
49+
TIMESTAMP=$(date -u +%Y-%m-%dT%H-%M)
50+
SHORT_SHA=$(git rev-parse --short HEAD)
51+
echo "BUILD_ID=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_ENV
52+
echo "build_id=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT
53+
54+
- name: Execute the Dockerfile
55+
working-directory: node
56+
run: |
57+
docker build -t node24_build -f ./Dockerfile.Node24 .
58+
59+
- name: Extract resources
60+
run: |
61+
docker create --name temp_node_extract node24_build
62+
docker cp temp_node_extract:/usr/src/node/node-install $GITHUB_WORKSPACE/node-install
63+
docker rm temp_node_extract
64+
65+
- name: Archive Node
66+
run: |
67+
mkdir -p artifacts
68+
FILENAME=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}.tar.xz
69+
FILENAME_LATEST=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz
70+
tar -C node-install -cJf artifacts/$FILENAME .
71+
cp artifacts/$FILENAME artifacts/$FILENAME_LATEST
72+
echo "NODE_ARCHIVE=$FILENAME" >> $GITHUB_ENV
73+
echo "NODE_ARCHIVE_LATEST=$FILENAME_LATEST" >> $GITHUB_ENV
74+
75+
- name: Upload Node archive
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}
79+
path: artifacts/${{ env.NODE_ARCHIVE }}
80+
81+
- name: Upload Node archive latest
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST
85+
path: artifacts/${{ env.NODE_ARCHIVE_LATEST }}
86+
87+
- name: Upload Node archive to release
88+
uses: softprops/action-gh-release@v1
89+
with:
90+
name: node-${{ env.NODE_VERSION }}-LATEST
91+
tag_name: node-${{ env.NODE_VERSION }}-release
92+
files: ./artifacts/${{ env.NODE_ARCHIVE_LATEST }}
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile.Fibers

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Stage 1
2+
FROM ubuntu:20.04 AS base
3+
4+
# Set non-interactive mode to avoid prompts during installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install necessary dependencies
8+
RUN apt-get update
9+
RUN apt-get install -y software-properties-common
10+
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
11+
RUN apt-get update
12+
RUN apt-get install -y build-essential python3 python3-distutils g++-10 make curl git pkg-config libssl-dev libffi-dev libgmp-dev libtool autoconf automake cmake wget xz-utils unzip vim
13+
14+
# Copy local Node.js source into the image
15+
WORKDIR /usr/src/node
16+
COPY node.tar.xz .
17+
18+
RUN mkdir -p node-install && tar -C node-install -xJf node.tar.xz
19+
20+
ENV PATH="/usr/src/node/node-install/usr/local/bin:$PATH"
21+
22+
RUN which node
23+
RUN node -v
24+
RUN node -p "process.arch"
25+
RUN echo -------------------
26+
RUN git clone --branch jackstrohm_node20_fibers --depth 1 https://github.com/asana/node-fibers.git node-fibers
27+
28+
WORKDIR /usr/src/node/node-fibers
29+
RUN npm install --nodedir="/usr/src/node/node-install/usr/local"
30+
RUN npm test || true
31+
RUN rm bin/repl
32+
RUN find .
33+
34+
35+
CMD ["bash"]

Dockerfile.Node24

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Stage 1
2+
FROM ubuntu:20.04 AS base
3+
4+
# Set non-interactive mode to avoid prompts during installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install necessary dependencies
8+
RUN apt-get update
9+
RUN apt-get install -y software-properties-common
10+
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
11+
RUN apt-get update && apt-get install -y build-essential python3 python3-distutils g++-10 make curl git pkg-config libssl-dev libffi-dev libgmp-dev libtool autoconf automake cmake wget xz-utils unzip vim
12+
RUN rm -rf /var/lib/apt/lists/*
13+
14+
# Set g++ 10 as the default
15+
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
16+
17+
# Copy local Node.js source into the image
18+
WORKDIR /usr/src/node
19+
COPY . .
20+
21+
# Disable maglev for fibers compatibility - maglev uses thread_local and stack manipulation
22+
# that conflicts with fiber context switching
23+
RUN ./configure --experimental-enable-pointer-compression --v8-disable-maglev
24+
RUN make -j4 install DESTDIR=./node-install
25+
26+
CMD ["bash"]

Dockerfile.Packages

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Stage 1
2+
FROM ubuntu:20.04 AS base
3+
4+
# Set non-interactive mode to avoid prompts during installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install necessary dependencies
8+
RUN apt-get update
9+
RUN apt-get install -y software-properties-common
10+
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
11+
RUN apt-get update
12+
RUN apt-get install -y build-essential python3 python3-distutils g++-10 make curl git pkg-config libssl-dev libffi-dev libgmp-dev libtool autoconf automake cmake wget xz-utils unzip vim
13+
14+
# Copy local Node.js source into the image
15+
WORKDIR /usr/src/node
16+
COPY node.tar.xz .
17+
18+
RUN mkdir -p node-install && tar -C node-install -xJf node.tar.xz
19+
20+
ENV PATH="/usr/src/node/node-install/usr/local/bin:$PATH"
21+
22+
RUN which node
23+
RUN node -v
24+
RUN node -p "process.arch"
25+
RUN echo -------------------
26+
27+
RUN npm i --nodedir="/usr/src/node/node-install/usr/local" bcrypt@5.1.0
28+
RUN npm i --nodedir="/usr/src/node/node-install/usr/local" cld@2.9.1
29+
RUN npm i --nodedir="/usr/src/node/node-install/usr/local" unix-dgram@2.0.6
30+
31+
RUN ls
32+
RUN ls node_modules
33+
34+
CMD ["bash"]

deps/v8/src/base/platform/platform.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,13 @@ class V8_BASE_EXPORT Thread {
596596
static LocalStorageKey CreateThreadLocalKey();
597597
static void DeleteThreadLocalKey(LocalStorageKey key);
598598
static void* GetThreadLocal(LocalStorageKey key);
599+
static int GetThreadLocalInt(LocalStorageKey key) {
600+
return static_cast<int>(reinterpret_cast<intptr_t>(GetThreadLocal(key)));
601+
}
599602
static void SetThreadLocal(LocalStorageKey key, void* value);
603+
static void SetThreadLocalInt(LocalStorageKey key, int value) {
604+
SetThreadLocal(key, reinterpret_cast<void*>(static_cast<intptr_t>(value)));
605+
}
600606
static bool HasThreadLocal(LocalStorageKey key) {
601607
return GetThreadLocal(key) != nullptr;
602608
}

deps/v8/src/execution/isolate-inl.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@
2626
namespace v8::internal {
2727

2828
// static
29-
V8_INLINE Isolate::PerIsolateThreadData*
30-
Isolate::CurrentPerIsolateThreadData() {
31-
return g_current_per_isolate_thread_data_;
32-
}
29+
// Commented out for fibers support - these are now non-inline in isolate.h
30+
// using LocalStorageKey instead of thread_local
31+
//V8_INLINE Isolate::PerIsolateThreadData*
32+
//Isolate::CurrentPerIsolateThreadData() {
33+
// return g_current_per_isolate_thread_data_;
34+
//}
3335

3436
// static
35-
V8_INLINE Isolate* Isolate::Current() {
36-
Isolate* isolate = TryGetCurrent();
37-
DCHECK_NOT_NULL(isolate);
38-
return isolate;
39-
}
37+
//V8_INLINE Isolate* Isolate::Current() {
38+
// Isolate* isolate = TryGetCurrent();
39+
// DCHECK_NOT_NULL(isolate);
40+
// return isolate;
41+
//}
4042

41-
bool Isolate::IsCurrent() const { return this == TryGetCurrent(); }
43+
//bool Isolate::IsCurrent() const { return this == TryGetCurrent(); }
4244

4345
void Isolate::set_context(Tagged<Context> context) {
4446
DCHECK(context.is_null() || IsContext(context));

0 commit comments

Comments
 (0)