Skip to content

build: commit some android build and test fixtures #57748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions android-patches/common.gypi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/common.gypi b/common.gypi
index 5e39ad3f09..1e535f48a8 100644
--- a/common.gypi
+++ b/common.gypi
@@ -520,11 +520,11 @@
}],
['_toolset=="host"', {
'conditions': [
- [ 'host_arch=="ia32"', {
+ [ 'host_arch=="ia32" or (target_arch=="ia32" or target_arch=="arm")', {
'cflags': [ '-m32' ],
'ldflags': [ '-m32' ],
}],
- [ 'host_arch=="x64"', {
+ [ 'host_arch=="x64" and (target_arch=="x64" or target_arch=="arm64")', {
'cflags': [ '-m64' ],
'ldflags': [ '-m64' ],
}],
44 changes: 34 additions & 10 deletions android-patches/trap-handler.h.patch
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
--- trap-handler.h 2022-08-11 09:01:23.384000000 +0800
+++ fixed-trap-handler.h 2022-08-11 09:09:15.352000000 +0800
@@ -17,23 +17,7 @@
diff --git a/deps/v8/src/trap-handler/trap-handler.h b/deps/v8/src/trap-handler/trap-handler.h
index 74967a00c1..d4f3b40269 100644
--- a/deps/v8/src/trap-handler/trap-handler.h
+++ b/deps/v8/src/trap-handler/trap-handler.h
@@ -17,45 +17,7 @@ namespace v8 {
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
-// Arm64 (non-simulator) on Mac and Linux.
-#elif V8_TARGET_ARCH_ARM64 && V8_HOST_ARCH_ARM64 && \
- (V8_OS_DARWIN || (V8_OS_LINUX && !V8_OS_ANDROID))
-#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_LINUX || V8_OS_DARWIN || V8_OS_WIN) && \
- (!defined(_MSC_VER) || defined(__clang__))
-#define V8_TRAP_HANDLER_VIA_SIMULATOR
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Loong64 (non-simulator) on Linux.
-#elif V8_TARGET_ARCH_LOONG64 && V8_HOST_ARCH_LOONG64 && V8_OS_LINUX
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Loong64 simulator on x64 on Linux
-#elif V8_TARGET_ARCH_LOONG64 && V8_HOST_ARCH_X64 && V8_OS_LINUX
-#define V8_TRAP_HANDLER_VIA_SIMULATOR
-#define V8_TRAP_HANDLER_SUPPORTED true
-// RISCV64 (non-simulator) on Linux.
-#elif V8_TARGET_ARCH_RISCV64 && V8_HOST_ARCH_RISCV64 && V8_OS_LINUX && \
- !V8_OS_ANDROID
-#define V8_TRAP_HANDLER_SUPPORTED true
-// RISCV64 simulator on x64 on Linux
-#elif V8_TARGET_ARCH_RISCV64 && V8_HOST_ARCH_X64 && V8_OS_LINUX
-#define V8_TRAP_HANDLER_VIA_SIMULATOR
-#define V8_TRAP_HANDLER_SUPPORTED true
-// Everything else is unsupported.
-#else
#define V8_TRAP_HANDLER_SUPPORTED false
-#endif
// Setup for shared library export.
#if defined(BUILDING_V8_SHARED) && defined(V8_OS_WIN)

#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 android-patches/v8.gyp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
index 1dd0b971d4..36b7c704dd 100644
--- a/tools/v8_gypfiles/v8.gyp
+++ b/tools/v8_gypfiles/v8.gyp
@@ -1989,12 +1989,12 @@
],
}, { # 'OS!="win"'
'conditions': [
- ['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', {
+ ['_toolset == "host" and host_arch == "x64" and (target_arch == "x64" or target_arch == "arm64") or (_toolset == "target" and target_arch == "x64")', {
'sources': [
'<(V8_ROOT)/src/heap/base/asm/x64/push_registers_asm.cc',
],
}],
- ['_toolset == "host" and host_arch == "ia32" or _toolset == "target" and target_arch=="ia32"', {
+ ['_toolset == "host" and host_arch == "x64" and (target_arch == "arm" or target_arch == "ia32") or (_toolset == "target" and target_arch == "ia32")', {
'sources': [
'<(V8_ROOT)/src/heap/base/asm/ia32/push_registers_asm.cc',
],
13 changes: 11 additions & 2 deletions android_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
# TODO: In next version, it will be a JSON file listing all the patches, and then it will iterate through to apply them.
def patch_android():
print("- Patches List -")
print("[1] [deps/v8/src/trap-handler/trap-handler.h] related to https://github.com/nodejs/node/issues/36287")
print("[1] [common.gypi] related to cross-compiling for 32-bit architectures on 64-bit host")
print("[2] [deps/v8/src/trap-handler/trap-handler.h] related to https://github.com/nodejs/node/issues/36287")
print("[3] [tools/v8_gypfiles/v8.gyp] build correct push_registers_asm.cc when cross-compiling for 32-bit on 64-bit host")
if platform.system() == "Linux":
os.system('patch -f ./deps/v8/src/trap-handler/trap-handler.h < ./android-patches/trap-handler.h.patch')
patches = [
'./android-patches/common.gypi.patch',
'./android-patches/trap-handler.h.patch',
'./android-patches/v8.gyp.patch',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe both v8.gyp.patch and common.gypi.patch should be actually committed rather than being left as patch files. The reason why I made them as patch files is because I find them quite hacky and smelly. Would like to know what approach do you guys prefer.

]
for patch in patches:
print(f"Applying patch: {patch}")
os.system('patch -p1 < ' + patch)
print("\033[92mInfo: \033[0m" + "Tried to patch.")

if platform.system() != "Linux" and platform.system() != "Darwin":
Expand Down
2 changes: 2 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const isFreeBSD = process.platform === 'freebsd';
const isOpenBSD = process.platform === 'openbsd';
const isLinux = process.platform === 'linux';
const isMacOS = process.platform === 'darwin';
const isAndroid = process.platform === 'android';
const isASan = process.config.variables.asan === 1;
const isRiscv64 = process.arch === 'riscv64';
const isDebug = process.features.debug;
Expand Down Expand Up @@ -891,6 +892,7 @@ const common = {
isLinux,
isOpenBSD,
isMacOS,
isAndroid,
isPi,
isSunOS,
isWindows,
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-bind-privileged-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const cluster = require('cluster');
const net = require('net');
const { readFileSync } = require('fs');

if (common.isLinux) {
if (common.isLinux || common.isAndroid) {
try {
const unprivilegedPortStart = parseInt(readFileSync('/proc/sys/net/ipv4/ip_unprivileged_port_start'));
if (unprivilegedPortStart <= 42) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (process.getuid() === 0)

// Some systems won't have port 42 set as a privileged port, in that
// case, skip the test.
if (common.isLinux) {
if (common.isLinux || common.isAndroid) {
const { readFileSync } = require('fs');

try {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-bind-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const BUFFER_SIZE = 4096;
const sendBufferSize = socket.getSendBufferSize();

// note: linux will double the buffer size
const expectedBufferSize = common.isLinux ?
const expectedBufferSize = (common.isLinux || common.isAndroid) ?
BUFFER_SIZE * 2 : BUFFER_SIZE;
assert.strictEqual(recvBufferSize, expectedBufferSize);
assert.strictEqual(sendBufferSize, expectedBufferSize);
Expand Down
10 changes: 6 additions & 4 deletions test/parallel/test-dgram-membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// addSourceSpecificMembership with invalid groupAddress should throw
{
const socket = setup();
const errCode = (common.isAndroid || common.isOpenBSD || common.isFreeBSD) ? 'ENOSYS' : 'EINVAL';
assert.throws(() => {
socket.addSourceSpecificMembership(multicastAddress, '0');
}, {
code: 'EINVAL',
message: 'addSourceSpecificMembership EINVAL'
code: errCode,
message: `addSourceSpecificMembership ${errCode}`
});
socket.close();
}
Expand Down Expand Up @@ -144,11 +145,12 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// dropSourceSpecificMembership with invalid UDP should throw
{
const socket = setup();
const errCode = (common.isAndroid || common.isOpenBSD || common.isFreeBSD) ? 'ENOSYS' : 'EINVAL';
assert.throws(() => {
socket.dropSourceSpecificMembership(multicastAddress, '0');
}, {
code: 'EINVAL',
message: 'dropSourceSpecificMembership EINVAL'
code: errCode,
message: `dropSourceSpecificMembership ${errCode}`
});
socket.close();
}
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-socket-buffer-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function getExpectedError(type) {
socket.setSendBufferSize(10000);

// note: linux will double the buffer size
const expectedBufferSize = common.isLinux ? 20000 : 10000;
const expectedBufferSize = (common.isLinux || common.isAndroid) ? 20000 : 10000;
assert.strictEqual(socket.getRecvBufferSize(), expectedBufferSize);
assert.strictEqual(socket.getSendBufferSize(), expectedBufferSize);
socket.close();
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-readfile-eof.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
const common = require('../common');

if (common.isWindows || common.isAIX || common.isIBMi)
common.skip(`No /dev/stdin on ${process.platform}.`);
common.skip(`No /dev/fd/0 on ${process.platform}.`);

const assert = require('assert');
const fs = require('fs/promises');
const childType = ['child-encoding', 'child-non-encoding'];

if (process.argv[2] === childType[0]) {
fs.readFile('/dev/stdin', 'utf8').then((data) => {
fs.readFile('/dev/fd/0', 'utf8').then((data) => {
process.stdout.write(data);
});
return;
} else if (process.argv[2] === childType[1]) {
fs.readFile('/dev/stdin').then((data) => {
fs.readFile('/dev/fd/0').then((data) => {
process.stdout.write(data);
});
return;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-readfile-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const common = require('../common');
// Simulate `cat readfile.js | node readfile.js`

if (common.isWindows || common.isAIX || common.isIBMi)
common.skip(`No /dev/stdin on ${process.platform}.`);
common.skip(`No /dev/fd/0 on ${process.platform}.`);

const assert = require('assert');
const fs = require('fs');

if (process.argv[2] === 'child') {
fs.readFile('/dev/stdin', function(er, data) {
fs.readFile('/dev/fd/0', function(er, data) {
assert.ifError(er);
process.stdout.write(data);
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-readfile-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const common = require('../common');
// Simulate `cat readfile.js | node readfile.js`

if (common.isWindows || common.isAIX || common.isIBMi)
common.skip(`No /dev/stdin on ${process.platform}.`);
common.skip(`No /dev/fd/0 on ${process.platform}.`);

const assert = require('assert');
const fs = require('fs');

if (process.argv[2] === 'child') {
fs.readFile('/dev/stdin', common.mustSucceed((data) => {
fs.readFile('/dev/fd/0', common.mustSucceed((data) => {
process.stdout.write(data);
}));
return;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-readfilesync-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const common = require('../common');
// Simulate `cat readfile.js | node readfile.js`

if (common.isWindows || common.isAIX || common.isIBMi)
common.skip(`No /dev/stdin on ${process.platform}.`);
common.skip(`No /dev/fd/0 on ${process.platform}.`);

const assert = require('assert');
const fs = require('fs');

if (process.argv[2] === 'child') {
process.stdout.write(fs.readFileSync('/dev/stdin', 'utf8'));
process.stdout.write(fs.readFileSync('/dev/fd/0', 'utf8'));
return;
}

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-realpath-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const common = require('../common');

if (common.isWindows || common.isAIX || common.isIBMi)
common.skip(`No /dev/stdin on ${process.platform}.`);
common.skip(`No /dev/fd/0 on ${process.platform}.`);

const assert = require('assert');

const { spawnSync } = require('child_process');

for (const code of [
`require('fs').realpath('/dev/stdin', (err, resolvedPath) => {
`require('fs').realpath('/dev/fd/0', (err, resolvedPath) => {
if (err) {
console.error(err);
process.exit(1);
Expand All @@ -20,7 +20,7 @@ for (const code of [
}
});`,
`try {
if (require('fs').realpathSync('/dev/stdin')) {
if (require('fs').realpathSync('/dev/fd/0')) {
process.exit(2);
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-constants-noatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const common = require('../common');
const assert = require('assert');
const constants = require('fs').constants;

if (common.isLinux) {
if (common.isLinux || common.isAndroid) {
assert('O_NOATIME' in constants);
assert.strictEqual(constants.O_NOATIME, 0x40000);
} else {
Expand Down
1 change: 1 addition & 0 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (!isMainThread) {

const expectFilePath = common.isWindows ||
common.isLinux ||
common.isAndroid ||
common.isMacOS ||
common.isAIX;

Expand Down
3 changes: 2 additions & 1 deletion tools/v8_gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@
# Platforms that don't have Compare-And-Swap (CAS) support need to link atomic library
# to implement atomic memory access.
# Clang needs it for some atomic operations (https://clang.llvm.org/docs/Toolchain.html#atomics-library).
['(OS=="linux" and clang==1) or (v8_current_cpu in ["mips64", "mips64el", "arm", "riscv64", "loong64"])', {
['((OS=="linux" or OS=="android") and clang==1) or (v8_current_cpu in ["mips64", "mips64el", "ppc", "arm", "riscv64", "loong64"])', {
'link_settings': {
'libraries': ['-latomic', ],
},
Expand Down Expand Up @@ -1466,6 +1466,7 @@
'<(V8_ROOT)/src/base/platform/platform-posix.h',
'<(V8_ROOT)/src/base/platform/platform-posix-time.cc',
'<(V8_ROOT)/src/base/platform/platform-posix-time.h',
'<(V8_ROOT)/src/base/platform/platform-linux.h',
],
'link_settings': {
'target_conditions': [
Expand Down
Loading