Skip to content

Commit 29fad45

Browse files
committed
tools: rewrite js2c.cc in rust
1 parent 25443db commit 29fad45

File tree

8 files changed

+809
-1019
lines changed

8 files changed

+809
-1019
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,6 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
15041504
test/fixtures/*.c \
15051505
test/js-native-api/*/*.cc \
15061506
test/node-api/*/*.cc \
1507-
tools/js2c.cc \
15081507
tools/icu/*.cc \
15091508
tools/icu/*.h \
15101509
tools/code_cache/*.cc \

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ def make_bin_override():
26982698

26992699
print_verbose(output)
27002700

2701-
# Dump as JSON to allow js2c.cc read it as a simple json file.
2701+
# Dump as JSON to allow js2c to read it as a simple json file.
27022702
write('config.gypi', do_not_edit +
27032703
json.dumps(output, indent=2) + '\n')
27042704

lib/internal/bootstrap/realm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Internal JavaScript module loader:
3232
// - BuiltinModule: a minimal module system used to load the JavaScript core
3333
// modules found in lib/**/*.js and deps/**/*.js. All core modules are
34-
// compiled into the node binary via node_javascript.cc generated by js2c.cc,
34+
// compiled into the node binary via node_javascript.cc generated by js2c,
3535
// so they can be loaded faster without the cost of I/O. This class makes the
3636
// lib/internal/*, deps/internal/* modules and internalBinding() available by
3737
// default to core modules, and lets the core modules require itself via

node.gyp

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
'ossfuzz' : 'false',
4444
'linked_module_files': [
4545
],
46-
# We list the deps/ files out instead of globbing them in js2c.cc since we
46+
# We list the deps/ files out instead of globbing them in js2c.rs since we
4747
# only include a subset of all the files under these directories.
4848
# The lengths of their file names combined should not exceed the
4949
# Windows command length limit or there would be an error.
@@ -1552,40 +1552,55 @@
15521552
}, # nop
15531553
{
15541554
'target_name': 'node_js2c',
1555-
'type': 'executable',
1555+
'type': 'none',
15561556
'toolsets': ['host'],
1557-
'include_dirs': [
1558-
'tools',
1559-
'src',
1560-
],
1561-
'sources': [
1562-
'tools/js2c.cc',
1563-
'tools/executable_wrapper.h',
1564-
'src/embedded_data.h',
1565-
'src/embedded_data.cc',
1566-
'src/builtin_info.h',
1567-
'src/builtin_info.cc',
1557+
'variables': {
1558+
'node_js2c_rustc_flags': [
1559+
'--edition=2021',
1560+
'--crate-name',
1561+
'node_js2c',
1562+
'-C',
1563+
'opt-level=2',
1564+
],
1565+
},
1566+
'actions': [
1567+
{
1568+
'action_name': 'build_node_js2c',
1569+
'inputs': [
1570+
'tools/js2c.rs',
1571+
],
1572+
'outputs': [
1573+
'<(node_js2c_exec)',
1574+
],
1575+
'action': [
1576+
'rustc',
1577+
'<@(node_js2c_rustc_flags)',
1578+
'tools/js2c.rs',
1579+
'-o',
1580+
'<@(_outputs)',
1581+
],
1582+
},
15681583
],
15691584
'conditions': [
1570-
[ 'OS=="mac"', {
1571-
'libraries': [ '-framework CoreFoundation -framework Security' ],
1572-
}],
1573-
[ 'node_shared_simdutf=="false" and node_use_bundled_v8!="false"', {
1574-
'dependencies': [ 'tools/v8_gypfiles/v8.gyp:simdutf#host' ],
1575-
}],
1576-
[ 'node_shared_libuv=="false"', {
1577-
'dependencies': [ 'deps/uv/uv.gyp:libuv#host' ],
1578-
}],
15791585
[ 'OS in "linux mac openharmony"', {
1580-
'defines': ['NODE_JS2C_USE_STRING_LITERALS'],
1586+
'variables': {
1587+
'node_js2c_rustc_flags+': [
1588+
'--cfg',
1589+
'node_js2c_use_string_literals',
1590+
],
1591+
},
15811592
}],
15821593
[ 'debug_node=="true"', {
1583-
'cflags!': [ '-O3' ],
1584-
'cflags': [ '-g', '-O0' ],
1585-
'defines': [ 'DEBUG' ],
1586-
'xcode_settings': {
1587-
'OTHER_CFLAGS': [
1588-
'-g', '-O0'
1594+
'variables': {
1595+
'node_js2c_rustc_flags!': [
1596+
'-C',
1597+
'opt-level=2',
1598+
],
1599+
'node_js2c_rustc_flags+': [
1600+
'-C',
1601+
'debuginfo=2',
1602+
'-C',
1603+
'opt-level=0',
15891604
],
15901605
},
15911606
}],

src/node_builtins.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ using BuiltinSourceMap = std::map<std::string, BuiltinSource>;
7979
using BuiltinCodeCacheMap =
8080
std::unordered_map<std::string, BuiltinCodeCacheData>;
8181

82-
// Generated by tools/js2c.cc as node_javascript.cc
82+
// Generated by tools/js2c as node_javascript.cc
8383
void RegisterExternalReferencesForInternalizedBuiltinCode(
8484
ExternalReferenceRegistry* registry);
8585

@@ -139,7 +139,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader {
139139
// Only allow access from friends.
140140
friend class CodeCacheBuilder;
141141

142-
// Generated by tools/js2c.cc as node_javascript.cc
142+
// Generated by tools/js2c as node_javascript.cc
143143
void LoadJavaScriptSource(); // Loads data into source_
144144
UnionBytes GetConfig(); // Return data for config.gypi
145145

0 commit comments

Comments
 (0)