From c288eb4aa47000d047ad3faa7da5c6c07cede4d0 Mon Sep 17 00:00:00 2001 From: Vektor Date: Tue, 23 Apr 2024 14:33:10 +0200 Subject: [PATCH] initial commit --- .github/workflows/build.yml | 92 ++++++++++++++++++++++++++++++++++ .gitmodules | 3 ++ node | 1 + patches/enable_rtti.patch | 27 ++++++++++ patches/internal_modules.patch | 19 +++++++ patches/rename_output.patch | 76 ++++++++++++++++++++++++++++ patches/version_suffix.patch | 13 +++++ 7 files changed, 231 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .gitmodules create mode 160000 node create mode 100644 patches/enable_rtti.patch create mode 100644 patches/internal_modules.patch create mode 100644 patches/rename_output.patch create mode 100644 patches/version_suffix.patch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eb4bfdc --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,92 @@ +name: Build libnode + +on: + push: + tags: + - 'v*' + +jobs: + build: + strategy: + fail-fast: false + matrix: + arch: [x64] + os: [ubuntu-latest, windows-latest] + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Setup alpine + uses: jirutka/setup-alpine@v1 + if: runner.os != 'Windows' + with: + branch: v3.16 + packages: > + git bash binutils-gold curl gnupg libgcc linux-headers make python3 ccache xz libatomic + clang clang-dev clang-libs llvm13-dev lld + libc-dev musl musl-dev musl-dbg gcc g++ + + - name: Apply patches + shell: bash + working-directory: ./node + run: | + git apply --reject --whitespace=fix ../patches/enable_rtti.patch + git apply --reject --whitespace=fix ../patches/internal_modules.patch + git apply --reject --whitespace=fix ../patches/rename_output.patch + git apply --reject --whitespace=fix ../patches/version_suffix.patch + + - name: Build project + if: runner.os != 'Windows' + working-directory: ./node + shell: alpine.sh {0} + run: | + export CC="clang" + export CXX="clang++" + export CXXFLAGS="-g -mssse3 -std=c++17" + export LDFLAGS="-m64 -lstdc++ -Wl,--build-id -fuse-ld=lld" + ./configure --shared + make -j4 + + - name: Install NASM + uses: ilammy/setup-nasm@v1 + if: runner.os == 'Windows' + + - name: Build + if: runner.os == 'Windows' + shell: bash + working-directory: ./node + run: ./vcbuild.bat release x64 dll no-cctest + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: libnode-${{ runner.os }}-${{ matrix.arch }} + path: ./node/out/Release + + release: + runs-on: ubuntu-latest + needs: build + permissions: + contents: write + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: | + ${{ github.workspace }}/libnode-Windows-x64/libnode20.dll + ${{ github.workspace }}/libnode-Windows-x64/libnode20.lib + ${{ github.workspace }}/libnode-Windows-x64/libnode20.pdb + ${{ github.workspace }}/libnode-Linux-x64/libnode20.so + + - name: Delete artifacts + uses: geekyeggo/delete-artifact@v5 + with: + name: libnode-* + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..86e1cf6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "node"] + path = node + url = https://github.com/nodejs/node.git diff --git a/node b/node new file mode 160000 index 0000000..b3f0c61 --- /dev/null +++ b/node @@ -0,0 +1 @@ +Subproject commit b3f0c612c8af7be46148f54604710bd5c6e2464f diff --git a/patches/enable_rtti.patch b/patches/enable_rtti.patch new file mode 100644 index 0000000..e96e67d --- /dev/null +++ b/patches/enable_rtti.patch @@ -0,0 +1,27 @@ +diff --git a/common.gypi b/common.gypi +index efcd8da848..946952d720 100644 +--- a/common.gypi ++++ b/common.gypi +@@ -439,7 +439,7 @@ + }], + [ 'OS in "linux freebsd openbsd solaris android aix os400 cloudabi"', { + 'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ], +- 'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++17' ], ++ 'cflags_cc': [ '-fno-exceptions' ], + 'defines': [ '__STDC_FORMAT_MACROS' ], + 'ldflags': [ '-rdynamic' ], + 'target_conditions': [ +diff --git a/tools/v8_gypfiles/features.gypi b/tools/v8_gypfiles/features.gypi +index c768d7a0f1..c40752b4b6 100644 +--- a/tools/v8_gypfiles/features.gypi ++++ b/tools/v8_gypfiles/features.gypi +@@ -318,7 +318,8 @@ + + # Enable advanced BigInt algorithms, costing about 10-30 KiB binary size + # depending on platform. +- 'v8_advanced_bigint_algorithms%': 1 ++ 'v8_advanced_bigint_algorithms%': 1, ++ 'use_rtti%': 1 + }, + + 'target_defaults': { diff --git a/patches/internal_modules.patch b/patches/internal_modules.patch new file mode 100644 index 0000000..ecaa03a --- /dev/null +++ b/patches/internal_modules.patch @@ -0,0 +1,19 @@ +diff --git a/lib/internal/bootstrap/realm.js b/lib/internal/bootstrap/realm.js +index 9cb6a8add7..6090473d7d 100644 +--- a/lib/internal/bootstrap/realm.js ++++ b/lib/internal/bootstrap/realm.js +@@ -209,12 +209,12 @@ const getOwn = (target, property, receiver) => { + + const publicBuiltinIds = builtinIds + .filter((id) => +- !StringPrototypeStartsWith(id, 'internal/') && ++ !StringPrototypeStartsWith(id, 'yespls/') && + !experimentalModuleList.has(id), + ); + // Do not expose the loaders to user land even with --expose-internals. + const internalBuiltinIds = builtinIds +- .filter((id) => StringPrototypeStartsWith(id, 'internal/') && id !== selfId); ++ .filter((id) => StringPrototypeStartsWith(id, 'yespls/') && id !== selfId); + + // When --expose-internals is on we'll add the internal builtin ids to these. + let canBeRequiredByUsersList = new SafeSet(publicBuiltinIds); diff --git a/patches/rename_output.patch b/patches/rename_output.patch new file mode 100644 index 0000000..16b9e47 --- /dev/null +++ b/patches/rename_output.patch @@ -0,0 +1,76 @@ +diff --git a/node.gyp b/node.gyp +index 4aac64089c..8fa6ab3e81 100644 +--- a/node.gyp ++++ b/node.gyp +@@ -25,7 +25,7 @@ + 'node_v8_options%': '', + 'node_enable_v8_vtunejit%': 'false', + 'node_core_target_name%': 'node', +- 'node_lib_target_name%': 'libnode', ++ 'node_lib_target_name%': 'libnode20', + 'node_intermediate_lib_type%': 'static_library', + 'node_builtin_modules_path%': '', + 'linked_module_files': [ + +diff --git a/tools/install.py b/tools/install.py +index 17b0947aac..3e49ce2d74 100755 +--- a/tools/install.py ++++ b/tools/install.py +@@ -151,31 +151,31 @@ def files(options, action): + + if 'true' == options.variables.get('node_shared'): + if options.is_win: +- action(options, [os.path.join(options.build_dir, 'libnode.dll')], 'bin/libnode.dll') +- action(options, [os.path.join(options.build_dir, 'libnode.lib')], 'lib/libnode.lib') ++ action(options, [os.path.join(options.build_dir, 'libnode20.dll')], 'bin/libnode20.dll') ++ action(options, [os.path.join(options.build_dir, 'libnode20.lib')], 'lib/libnode20.lib') + elif sys.platform == 'zos': + # GYP will output to lib.target; see _InstallableTargetInstallPath + # function in tools/gyp/pylib/gyp/generator/make.py + output_prefix = os.path.join(options.build_dir, 'lib.target') + +- output_lib = 'libnode.' + options.variables.get('shlib_suffix') ++ output_lib = 'libnode20.' + options.variables.get('shlib_suffix') + action(options, [os.path.join(output_prefix, output_lib)], os.path.join('lib', output_lib)) + +- # create libnode.x that references libnode.so (C++ addons compat) ++ # create libnode20.x that references libnode20.so (C++ addons compat) + os.system(os.path.dirname(os.path.realpath(__file__)) + + '/zos/modifysidedeck.sh ' + + abspath(options.install_path, 'lib', output_lib) + ' ' + +- abspath(options.install_path, 'lib/libnode.x') + ' libnode.so') ++ abspath(options.install_path, 'lib/libnode20.x') + ' libnode20.so') + +- # install libnode.version.so +- so_name = 'libnode.' + re.sub(r'\.x$', '.so', options.variables.get('shlib_suffix')) ++ # install libnode20.version.so ++ so_name = 'libnode20.' + re.sub(r'\.x$', '.so', options.variables.get('shlib_suffix')) + action(options, [os.path.join(output_prefix, so_name)], options.variables.get('libdir') + '/' + so_name) + +- # create symlink of libnode.so -> libnode.version.so (C++ addons compat) +- link_path = abspath(options.install_path, 'lib/libnode.so') ++ # create symlink of libnode20.so -> libnode20.version.so (C++ addons compat) ++ link_path = abspath(options.install_path, 'lib/libnode20.so') + try_symlink(options, so_name, link_path) + else: +- output_lib = 'libnode.' + options.variables.get('shlib_suffix') ++ output_lib = 'libnode20.' + options.variables.get('shlib_suffix') + action(options, [os.path.join(options.build_dir, output_lib)], + os.path.join(options.variables.get('libdir'), output_lib)) + + +diff --git a/vcbuild.bat b/vcbuild.bat +index 75f0850b01..3baa17461f 100644 +--- a/vcbuild.bat ++++ b/vcbuild.bat +@@ -451,8 +451,8 @@ if errorlevel 1 echo Cannot copy nodevars.bat && goto package_error + copy /Y ..\tools\msvs\install_tools\*.* %TARGET_NAME%\ > nul + if errorlevel 1 echo Cannot copy install_tools scripts && goto package_error + if defined dll ( +- copy /Y libnode.dll %TARGET_NAME%\ > nul +- if errorlevel 1 echo Cannot copy libnode.dll && goto package_error ++ copy /Y libnode20.dll %TARGET_NAME%\ > nul ++ if errorlevel 1 echo Cannot copy libnode20.dll && goto package_error + + mkdir %TARGET_NAME%\Release > nul + copy /Y node.def %TARGET_NAME%\Release\ > nul diff --git a/patches/version_suffix.patch b/patches/version_suffix.patch new file mode 100644 index 0000000..55c41a0 --- /dev/null +++ b/patches/version_suffix.patch @@ -0,0 +1,13 @@ +diff --git a/configure.py b/configure.py +index 00c8513d68..0794bab18e 100755 +--- a/configure.py ++++ b/configure.py +@@ -1428,7 +1428,7 @@ def configure_node(o): + elif sys.platform.startswith('zos'): + shlib_suffix = '%s.x' + else: +- shlib_suffix = 'so.%s' ++ shlib_suffix = 'so' + if '%s' in shlib_suffix: + shlib_suffix %= node_module_version +