Skip to content

Commit

Permalink
new package: nodejs-20
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Jun 15, 2024
1 parent 07e8b18 commit 9dcdfe0
Show file tree
Hide file tree
Showing 35 changed files with 990 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tur/nodejs-20/avoid-ficlone-ioctl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff '--color=auto' -uNr node-v18.0.0.orig/deps/uv/src/unix/fs.c node-v18.0.0/deps/uv/src/unix/fs.c
--- node-v18.0.0.orig/deps/uv/src/unix/fs.c 2022-04-21 15:15:32.641869790 +0530
+++ node-v18.0.0/deps/uv/src/unix/fs.c 2022-04-21 15:28:38.058124015 +0530
@@ -1339,6 +1339,7 @@
#endif /* !__linux__ */
}

+#ifndef __ANDROID__
#ifdef FICLONE
if (req->flags & UV_FS_COPYFILE_FICLONE ||
req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
@@ -1359,6 +1360,7 @@
goto out;
}
#endif
+#endif

bytes_to_send = src_statsbuf.st_size;
in_offset = 0;
85 changes: 85 additions & 0 deletions tur/nodejs-20/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
TERMUX_PKG_HOMEPAGE=https://nodejs.org/
TERMUX_PKG_DESCRIPTION="Open Source, cross-platform JavaScript runtime environment"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux-user-repository"
TERMUX_PKG_VERSION=20.14.0
TERMUX_PKG_SRCURL=https://nodejs.org/dist/v${TERMUX_PKG_VERSION}/node-v${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_SHA256=08655028f0d8436e88163f9186044d635d3f36a85ee528f36bd05b6c5e46c1bb
# Note that we do not use a shared libuv to avoid an issue with the Android
# linker, which does not use symbols of linked shared libraries when resolving
# symbols on dlopen(). See https://github.com/termux/termux-packages/issues/462.
TERMUX_PKG_DEPENDS="libc++, openssl, c-ares, zlib"
TERMUX_PKG_CONFLICTS="nodejs, nodejs-current"
_INSTALL_PREFIX=opt/nodejs-20
TERMUX_PKG_RM_AFTER_INSTALL="
$_INSTALL_PREFIX/lib/node_modules/npm/html
$_INSTALL_PREFIX/lib/node_modules/npm/make.bat
$_INSTALL_PREFIX/share/systemtap
$_INSTALL_PREFIX/lib/dtrace
"
TERMUX_PKG_BUILD_IN_SRC=true

termux_step_pre_configure() {
termux_setup_ninja
}

termux_step_configure() {
local DEST_CPU
if [ $TERMUX_ARCH = "arm" ]; then
DEST_CPU="arm"
elif [ $TERMUX_ARCH = "i686" ]; then
DEST_CPU="ia32"
elif [ $TERMUX_ARCH = "aarch64" ]; then
DEST_CPU="arm64"
elif [ $TERMUX_ARCH = "x86_64" ]; then
DEST_CPU="x64"
else
termux_error_exit "Unsupported arch '$TERMUX_ARCH'"
fi

export GYP_DEFINES="host_os=linux"
local _host_compiler_suffix=""
if [ $TERMUX_ARCH_BITS = 32 ]; then
_host_compiler_suffix="-m32"
fi
export CC_host="gcc $_host_compiler_suffix"
export CXX_host="g++ $_host_compiler_suffix"
export LINK_host="g++ $_host_compiler_suffix"

mkdir -p $TERMUX_PREFIX/$_INSTALL_PREFIX
LDFLAGS="-Wl,-rpath=$TERMUX_PREFIX/$_INSTALL_PREFIX/lib $LDFLAGS"

# See note above TERMUX_PKG_DEPENDS why we do not use a shared libuv
# When building with ninja, build.ninja is geenrated for both Debug and Release builds.
./configure \
--prefix=$TERMUX_PREFIX/$_INSTALL_PREFIX \
--dest-cpu=$DEST_CPU \
--dest-os=android \
--shared-cares \
--shared-openssl \
--shared-zlib \
--with-intl=full-icu \
--cross-compiling \
--ninja

sed -i \
-e "s|\-I$TERMUX_PREFIX/include| |g" \
-e "s|\-L$TERMUX_PREFIX/lib| |g" \
$(find $TERMUX_PKG_SRCDIR/out/{Release,Debug}/obj.host -name '*.ninja')
}

termux_step_make() {
if [ "${TERMUX_DEBUG_BUILD}" = "true" ]; then
ninja -C out/Debug -j "${TERMUX_MAKE_PROCESSES}"
else
ninja -C out/Release -j "${TERMUX_MAKE_PROCESSES}"
fi
}

termux_step_make_install() {
if [ "${TERMUX_DEBUG_BUILD}" = "true" ]; then
python tools/install.py install --dest-dir="" --prefix "$TERMUX_PREFIX/$_INSTALL_PREFIX" --build-dir out/Debug/
else
python tools/install.py install --dest-dir="" --prefix "$TERMUX_PREFIX/$_INSTALL_PREFIX" --build-dir out/Release/
fi
}
13 changes: 13 additions & 0 deletions tur/nodejs-20/common.gypi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- ./common.gypi.orig 2024-02-18 23:11:41.173679151 +0530
+++ ./common.gypi 2024-02-18 23:11:53.907570677 +0530
@@ -237,10 +237,6 @@
},],
],
},],
- ['OS == "android"', {
- 'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
- 'ldflags': [ '-fPIC' ]
- }],
],
'msvs_settings': {
'VCCLCompilerTool': {
17 changes: 17 additions & 0 deletions tur/nodejs-20/deps-npm-lib-cli-entry.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff -u -r ../node-v20.14.0/deps/npm/lib/cli/entry.js ./deps/npm/lib/cli/entry.js
--- ../node-v20.14.0/deps/npm/lib/cli/entry.js 2024-05-28 04:57:54.000000000 +0000
+++ ./deps/npm/lib/cli/entry.js 2024-05-30 19:57:14.804332523 +0000
@@ -64,13 +64,6 @@

const execPromise = npm.exec(command, args)

- // this is async but we dont await it, since its ok if it doesnt
- // finish before the command finishes running. it uses command and argv
- // so it must be initiated here, after the command name is set
- const updateNotifier = require('./update-notifier.js')
- // eslint-disable-next-line promise/catch-or-return
- updateNotifier(npm).then((msg) => (npm.updateNotification = msg))
-
await execPromise
return exitHandler()
} catch (err) {
21 changes: 21 additions & 0 deletions tur/nodejs-20/deps-npm-lib-commands-install.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- ./deps/npm/lib/commands/install.js.orig 2023-01-17 18:37:18.553261550 +0530
+++ ./deps/npm/lib/commands/install.js 2023-01-17 18:44:48.711879839 +0530
@@ -118,6 +118,18 @@
throw e
}
}
+ try {
+ if (forced) {
+ log.warn(
+ 'install',
+ `Force installing npm version unpatched version of ${npmManifest.version}. This is very likely to break installation of global packages using npm. See https://github.com/termux/termux-packages/issues/13293`
+ )
+ } else {
+ throw new Error("Can't install npm globally as it will very likely break installation of global packages using npm. See https://github.com/termux/termux-packages/issues/13293")
+ }
+ } catch(e) {
+ throw e
+ }
}

// don't try to install the prefix into itself
12 changes: 12 additions & 0 deletions tur/nodejs-20/deps-uv-src-unix-core.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff '--color=auto' -uNr node-v18.0.0.orig/deps/uv/src/unix/core.c node-v18.0.0/deps/uv/src/unix/core.c
--- node-v18.0.0.orig/deps/uv/src/unix/core.c 2022-04-21 15:15:32.621869790 +0530
+++ node-v18.0.0/deps/uv/src/unix/core.c 2022-04-21 15:29:22.728123998 +0530
@@ -1125,7 +1125,7 @@

/* No temp environment variables defined */
#if defined(__ANDROID__)
- buf = "/data/local/tmp";
+ buf = "@TERMUX_PREFIX@/tmp";
#else
buf = "/tmp";
#endif
26 changes: 26 additions & 0 deletions tur/nodejs-20/deps-uv-src-unix-process.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- ./deps/uv/src/unix/process.c.orig 2023-01-07 17:02:14.172196070 +0530
+++ ./deps/uv/src/unix/process.c 2023-01-07 17:04:50.305214673 +0530
@@ -351,23 +351,6 @@
if (options->cwd != NULL && chdir(options->cwd))
uv__write_errno(error_fd);

- if (options->flags & (UV_PROCESS_SETUID | UV_PROCESS_SETGID)) {
- /* When dropping privileges from root, the `setgroups` call will
- * remove any extraneous groups. If we don't call this, then
- * even though our uid has dropped, we may still have groups
- * that enable us to do super-user things. This will fail if we
- * aren't root, so don't bother checking the return value, this
- * is just done as an optimistic privilege dropping function.
- */
- SAVE_ERRNO(setgroups(0, NULL));
- }
-
- if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid))
- uv__write_errno(error_fd);
-
- if ((options->flags & UV_PROCESS_SETUID) && setuid(options->uid))
- uv__write_errno(error_fd);
-
if (options->env != NULL)
environ = options->env;

28 changes: 28 additions & 0 deletions tur/nodejs-20/deps-uv-uv.gyp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- ./deps/uv/uv.gyp 2023-01-06 04:16:46.000000000 +0530
+++ ./deps/uv/uv.gyp.mod 2023-01-10 19:53:16.953276157 +0530
@@ -40,7 +40,7 @@
{
'target_name': 'libuv',
'type': '<(uv_library)',
- 'include_dirs': [
+ 'include_dirs+': [
'include',
'src/',
],
@@ -55,7 +55,7 @@
'<@(shared_unix_defines)',
'<@(shared_zos_defines)',
],
- 'include_dirs': [ 'include' ],
+ 'include_dirs+': [ 'include' ],
'conditions': [
['OS == "linux"', {
'defines': [ '_POSIX_C_SOURCE=200112' ],
@@ -267,6 +266,7 @@
'src/unix/random-sysctl-linux.c',
'src/unix/epoll.c',
],
+ 'defines': [ '__USE_GNU' ],
'link_settings': {
'libraries': [ '-ldl' ],
},
12 changes: 12 additions & 0 deletions tur/nodejs-20/deps-v8-src-flags-flag-definitions.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff '--color=auto' -uNr node-v18.0.0.orig/deps/v8/src/flags/flag-definitions.h node-v18.0.0/deps/v8/src/flags/flag-definitions.h
--- node-v18.0.0.orig/deps/v8/src/flags/flag-definitions.h 2022-04-21 15:15:34.881869789 +0530
+++ node-v18.0.0/deps/v8/src/flags/flag-definitions.h 2022-04-21 15:43:52.827175160 +0530
@@ -2091,7 +2091,7 @@
#undef DEFINE_PERF_PROF_BOOL
#undef DEFINE_PERF_PROF_IMPLICATION

-DEFINE_STRING(gc_fake_mmap, "/tmp/__v8_gc__",
+DEFINE_STRING(gc_fake_mmap, "@TERMUX_PREFIX@/tmp/__v8_gc__",
"Specify the name of the file for fake gc mmap used in ll_prof")
DEFINE_BOOL(log_internal_timer_events, false, "Time internal events.")
DEFINE_IMPLICATION(log_internal_timer_events, prof)
11 changes: 11 additions & 0 deletions tur/nodejs-20/deps-v8-src-logging-log.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ./deps/v8/src/logging/log.cc.orig 2024-02-18 22:32:25.705899829 +0530
+++ ./deps/v8/src/logging/log.cc 2024-02-18 22:49:33.993837346 +0530
@@ -367,7 +367,7 @@
static uint64_t reference_count_;
};

-const char LinuxPerfBasicLogger::kFilenameFormatString[] = "/tmp/perf-%d.map";
+const char LinuxPerfBasicLogger::kFilenameFormatString[] = "@TERMUX_PREFIX@/tmp/perf-%d.map";
// Extra space for the PID in the filename
const int LinuxPerfBasicLogger::kFilenameBufferPadding = 16;

32 changes: 32 additions & 0 deletions tur/nodejs-20/deps-v8-src-trap-handler-trap-handler.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- ./deps/v8/src/trap-handler/trap-handler.h.orig 2024-02-18 22:32:25.709233278 +0530
+++ ./deps/v8/src/trap-handler/trap-handler.h 2024-02-18 22:51:32.229316245 +0530
@@ -17,29 +17,7 @@
namespace internal {
namespace trap_handler {

-// X64 on Linux, Windows, MacOS, FreeBSD.
-#if V8_HOST_ARCH_X64 && V8_TARGET_ARCH_X64 && \
- ((V8_OS_LINUX && !V8_OS_ANDROID) || V8_OS_WIN || V8_OS_DARWIN || \
- V8_OS_FREEBSD)
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Arm64 (non-simulator) on Mac.
-#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_ARM64 && V8_OS_DARWIN
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Arm64 simulator on x64 on Linux, Mac, or Windows.
-//
-// The simulator case uses some inline assembly code, which cannot be
-// compiled with MSVC, so don't enable the trap handler in that case.
-// (MSVC #defines _MSC_VER, but so does Clang when targeting Windows, hence
-// the check for __clang__.)
-#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_X64 && \
- (V8_OS_LINUX || V8_OS_DARWIN || V8_OS_WIN) && \
- (!defined(_MSC_VER) || defined(__clang__))
-#define V8_TRAP_HANDLER_VIA_SIMULATOR
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Everything else is unsupported.
-#else
#define V8_TRAP_HANDLER_SUPPORTED false
-#endif

#if V8_OS_ANDROID && V8_TRAP_HANDLER_SUPPORTED
// It would require some careful security review before the trap handler
19 changes: 19 additions & 0 deletions tur/nodejs-20/fix_multiple_definitions.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff '--color=auto' -uNr node-v18.0.0.orig/deps/uv/src/unix/sysinfo-memory.c node-v18.0.0/deps/uv/src/unix/sysinfo-memory.c
--- node-v18.0.0.orig/deps/uv/src/unix/sysinfo-memory.c 2022-04-21 15:15:32.611869790 +0530
+++ node-v18.0.0/deps/uv/src/unix/sysinfo-memory.c 2022-04-21 15:46:04.427175110 +0530
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <sys/sysinfo.h>

+#ifndef __ANDROID__
uint64_t uv_get_free_memory(void) {
struct sysinfo info;

@@ -32,6 +33,7 @@
return (uint64_t) info.freeram * info.mem_unit;
return 0;
}
+#endif

uint64_t uv_get_total_memory(void) {
struct sysinfo info;
12 changes: 12 additions & 0 deletions tur/nodejs-20/lib-child_process.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff '--color=auto' -uNr node-v18.0.0.orig/lib/child_process.js node-v18.0.0/lib/child_process.js
--- node-v18.0.0.orig/lib/child_process.js 2022-04-21 15:15:48.551869784 +0530
+++ node-v18.0.0/lib/child_process.js 2022-04-21 15:46:39.467175097 +0530
@@ -578,7 +578,7 @@
if (typeof options.shell === 'string')
file = options.shell;
else if (process.platform === 'android')
- file = '/system/bin/sh';
+ file = '@TERMUX_PREFIX@/bin/sh';
else
file = '/bin/sh';
args = ['-c', command];
11 changes: 11 additions & 0 deletions tur/nodejs-20/lib-os.js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- ./lib/os.js.orig 2023-02-02 02:40:18.000000000 +0530
+++ ./lib/os.js 2023-02-10 18:35:51.340175431 +0530
@@ -193,7 +193,7 @@
path = safeGetenv('TMPDIR') ||
safeGetenv('TMP') ||
safeGetenv('TEMP') ||
- '/tmp';
+ '@TERMUX_PREFIX@/tmp';
if (path.length > 1 && StringPrototypeEndsWith(path, '/'))
path = StringPrototypeSlice(path, 0, -1);
}
Loading

0 comments on commit 9dcdfe0

Please sign in to comment.