Skip to content

Commit 958e49a

Browse files
committed
[GR-48203] [GR-48310] Backport: Node.js fails to build on darwin-amd64; move native-image config to META-INF.
PullRequest: js/2910
2 parents dbac49a + b1cbacc commit 958e49a

File tree

13 files changed

+208
-43
lines changed

13 files changed

+208
-43
lines changed

ci.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ local graalNodeJs = import 'graal-nodejs/ci.jsonnet';
3737
NATIVE_IMAGES: ni,
3838
EXTRA_IMAGE_BUILDER_ARGUMENTS: eiba,
3939
},
40-
export_envvars:: [['set-export', key, self.envvars[key]] for key in std.objectFields(self.envvars) if std.length(self.envvars[key]) > 0],
40+
local has_svm = std.find('substratevm', self.suiteimports) != [],
41+
export_envvars:: [['set-export', key, self.envvars[key]] for key in std.objectFields(self.envvars) if std.length(self.envvars[key]) > 0 || (key == 'NATIVE_IMAGES' && has_svm)],
4142
suite_prefix:: error 'suite_prefix not set',
4243
cd:: '',
4344
cd_run:: if self.cd != '' then [['cd', self.cd]] else [],

common.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ targets +
6363

6464
darwin_amd64:: common.darwin_amd64 + self.common_deps + {
6565
environment+: {
66-
// for compatibility with macOS El Capitan
67-
MACOSX_DEPLOYMENT_TARGET: '10.11',
66+
// for compatibility with macOS High Sierra
67+
MACOSX_DEPLOYMENT_TARGET: '10.13',
6868
},
6969
capabilities+: ['darwin_mojave'],
7070
},
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# This file contains native-image arguments needed to build graal-js
2-
#
2+
# complementary to META-INF/native-image/org.graalvm.js/*
33

44
Requires = language:regex
55

66
JavaArgs = -Dpolyglot.image-build-time.PreinitializeContexts=js
7-
8-
Args = -H:MaxRuntimeCompileMethods=10000 \
9-
--initialize-at-build-time=com.oracle.truffle.js,com.oracle.js.parser,com.oracle.truffle.regex
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file contains native-image arguments needed to build graal-js
2+
3+
Args = -H:MaxRuntimeCompileMethods=10000 \
4+
--initialize-at-build-time=com.oracle.truffle.js,com.oracle.js.parser,com.oracle.truffle.regex

graal-nodejs/ci.jsonnet

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local cicommon = import '../ci/common.jsonnet';
77
cd:: 'graal-nodejs',
88
suite_prefix:: 'nodejs', # for build job names
99
// increase default timelimit on windows and darwin-amd64
10-
timelimit: if 'os' in self && (self.os == 'windows' || (self.os == 'darwin' && self.arch == 'amd64')) then '1:15:00' else '45:00',
10+
timelimit: if 'os' in self && (self.os == 'windows' || (self.os == 'darwin' && self.arch == 'amd64')) then '1:30:00' else '45:00',
1111
},
1212

1313
local ce = ci.ce,
@@ -51,7 +51,7 @@ local cicommon = import '../ci/common.jsonnet';
5151
['set-export', 'STANDALONE_HOME', ['mx', '--quiet', 'standalone-home', 'nodejs', '--type=jvm']],
5252
['${STANDALONE_HOME}/bin/node', '-e', "console.log('Hello, World!')"],
5353
['${STANDALONE_HOME}/bin/npm', '--version'],
54-
] + (if std.find('substratevm', super.suiteimports) != [] then [
54+
] + (if std.find('lib:graal-nodejs', super.nativeimages) != [] then [
5555
['set-export', 'STANDALONE_HOME', ['mx', '--quiet', 'standalone-home', 'nodejs', '--type=native']],
5656
['${STANDALONE_HOME}/bin/node', '-e', "console.log('Hello, World!')"],
5757
['${STANDALONE_HOME}/bin/npm', '--version'],
@@ -149,13 +149,13 @@ local cicommon = import '../ci/common.jsonnet';
149149
] +
150150
// mx makeinnodeenv requires NASM on Windows.
151151
[gateOnMain + excludePlatforms([common.windows_amd64]) + b for b in [
152-
graalNodeJs + buildAddons + testNode('addons', max_heap='8G') + {name: 'addons'},
153-
graalNodeJs + buildNodeAPI + testNode('node-api', max_heap='8G') + {name: 'node-api'},
154-
graalNodeJs + buildJSNativeAPI + testNode('js-native-api', max_heap='8G') + {name: 'js-native-api'},
152+
graalNodeJs + buildAddons + testNode('addons', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'addons'},
153+
graalNodeJs + buildNodeAPI + testNode('node-api', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'node-api'},
154+
graalNodeJs + buildJSNativeAPI + testNode('js-native-api', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'js-native-api'},
155155
]] +
156156
[gateOnMain + promoteToTarget(common.gate, [common.jdk21 + common.windows_amd64]) + b for b in [
157-
graalNodeJs + vm_env + build + testNode('async-hooks', max_heap='8G') + {name: 'async-hooks'},
158-
graalNodeJs + vm_env + build + testNode('es-module', max_heap='8G') + {name: 'es-module'},
157+
graalNodeJs + vm_env + build + testNode('async-hooks', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'async-hooks'},
158+
graalNodeJs + vm_env + build + testNode('es-module', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'es-module'},
159159
# We run the `sequential` tests with a smaller heap because `test/sequential/test-child-process-pass-fd.js` starts 80 child processes.
160160
graalNodeJs + vm_env + build + testNode('sequential', max_heap='8G') + maxHeapOnWindows('512M') + {name: 'sequential'} +
161161
excludePlatforms([common.darwin_amd64]), # times out on darwin-amd64

graal-nodejs/deps/ada/ada.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10446,7 +10446,11 @@ ada_warn_unused std::string to_string(ada::encoding_type type) {
1044610446
/* begin file src/helpers.cpp */
1044710447

1044810448
#include <algorithm>
10449+
#if __has_include(<charconv>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
1044910450
#include <charconv>
10451+
#else
10452+
#include "charconv_shim.h"
10453+
#endif
1045010454
#include <cstring>
1045110455
#include <sstream>
1045210456

graal-nodejs/deps/ada/ada.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4894,7 +4894,11 @@ ada_really_inline constexpr bool verify_dns_length(
48944894

48954895

48964896
#include <algorithm>
4897+
#if __has_include(<charconv>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
48974898
#include <charconv>
4899+
#else
4900+
#include "charconv_shim.h"
4901+
#endif
48984902
#include <iostream>
48994903
#include <optional>
49004904
#include <string>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
#ifndef CHARCONV_SHIM_H_
43+
#define CHARCONV_SHIM_H_
44+
45+
// Poor man's <charconv> substitute for unsigned integer types only.
46+
// Allows Ada to be compiled on pre-C++17 macOS <10.15 (GR-48310).
47+
48+
#warning "<charconv> not available, using alternative implementation"
49+
50+
#include <type_traits>
51+
#include <limits>
52+
#include <system_error> // std::errc
53+
#include <algorithm> // std::min
54+
55+
namespace charconv_shim {
56+
struct from_chars_result {
57+
const char* ptr;
58+
std::errc ec;
59+
};
60+
struct to_chars_result {
61+
char* ptr;
62+
std::errc ec;
63+
};
64+
65+
constexpr char to_lower(char x) {
66+
return (x | 0x20);
67+
}
68+
69+
template <typename UINT_T, UINT_T max = std::numeric_limits<UINT_T>::max(),
70+
typename std::enable_if<std::is_integral<UINT_T>::value, int>::type = 0,
71+
typename std::enable_if<!std::is_signed<UINT_T>::value, int>::type = 0>
72+
inline from_chars_result from_chars(const char* first, const char* last, UINT_T& value, int base = 10) {
73+
if (base < 2 || base > 36) {
74+
return {first, std::errc::invalid_argument};
75+
}
76+
const UINT_T mul_limit = max / base;
77+
UINT_T result = 0;
78+
auto cursor = first;
79+
auto ec = std::errc{};
80+
while (cursor < last) {
81+
char c = *cursor;
82+
char l = to_lower(c);
83+
char d;
84+
if (c >= '0' && c < '0' + std::min(base, 10)) {
85+
d = c - '0';
86+
} else if (base > 10 && l >= 'a' && l < 'a' + (base - 10)) {
87+
d = l - 'a';
88+
} else {
89+
break;
90+
}
91+
if (result > mul_limit) {
92+
// multiplication would result in integer overflow
93+
ec = std::errc::result_out_of_range;
94+
// advance until last valid digit
95+
}
96+
result *= base;
97+
if (result > max - d) {
98+
// addition would result in integer overflow
99+
ec = std::errc::result_out_of_range;
100+
// advance until last valid digit
101+
}
102+
result += d;
103+
++cursor;
104+
}
105+
if (cursor == first) {
106+
return {first, std::errc::invalid_argument};
107+
} else if (ec == std::errc{}) {
108+
value = result;
109+
}
110+
return {cursor, ec};
111+
}
112+
113+
template <typename UINT_T,
114+
typename std::enable_if<std::is_integral<UINT_T>::value, int>::type = 0,
115+
typename std::enable_if<!std::is_signed<UINT_T>::value, int>::type = 0>
116+
inline to_chars_result to_chars(char* first, char* last, UINT_T value, int base = 10) {
117+
if (base < 2 || base > 36) {
118+
return {first, std::errc::invalid_argument};
119+
}
120+
int length = 1;
121+
for (auto v = value; v >= base; v /= base) {
122+
++length;
123+
}
124+
if (last - first < length) {
125+
return {last, std::errc::value_too_large};
126+
}
127+
128+
const char *const digits = "0123456789abcdefghijklmnopqrstuvwxyz";
129+
last = first + length;
130+
char* cursor = last;
131+
if (value == 0) {
132+
*--cursor = '0';
133+
} else {
134+
for (auto v = value; v > 0; v /= base) {
135+
*--cursor = digits[v % base];
136+
}
137+
}
138+
return {last, {}};
139+
}
140+
}
141+
142+
namespace std {
143+
using ::charconv_shim::from_chars_result;
144+
using ::charconv_shim::to_chars_result;
145+
using ::charconv_shim::from_chars;
146+
using ::charconv_shim::to_chars;
147+
}
148+
149+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file contains native-image arguments needed to build graal-nodejs
2+
3+
Args = -H:MaxRuntimeCompileMethods=500 \
4+
--shared \
5+
--initialize-at-build-time=com.oracle.truffle.trufflenode

0 commit comments

Comments
 (0)