Skip to content

Commit 45f5ea3

Browse files
committed
build: add temporal_capi gyp
1 parent 6a7b965 commit 45f5ea3

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

configure.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,14 @@
10411041
default=None,
10421042
help='Use ccache for compiling on Windows. ')
10431043

1044+
# Rust toolchain options
1045+
parser.add_argument('--rust-toolchain-library-path',
1046+
action='store',
1047+
dest='rust_toolchain_library_path',
1048+
default=None,
1049+
help='Path to Rust toolchain libraries to link against when building ' +
1050+
'Node.js with Temporal support.')
1051+
10441052
(options, args) = parser.parse_known_args()
10451053

10461054
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -1440,8 +1448,8 @@ def host_arch_win():
14401448
return matchup.get(arch, 'x64')
14411449

14421450
def set_configuration_variable(configs, name, release=None, debug=None):
1443-
configs['Release'][name] = release
1444-
configs['Debug'][name] = debug
1451+
configs['Release']['variables'][name] = release
1452+
configs['Debug']['variables'][name] = debug
14451453

14461454
def configure_arm(o):
14471455
if options.arm_float_abi:
@@ -1772,6 +1780,12 @@ def configure_library(lib, output, pkgname=None):
17721780
output['libraries'] += pkg_libs.split()
17731781

17741782

1783+
def configure_rust(o, configs):
1784+
set_configuration_variable(configs, 'cargo_build_mode', release='release', debug='debug')
1785+
set_configuration_variable(configs, 'cargo_build_flags', release=['--release'], debug=[])
1786+
o['variables']['rust_toolchain_library_path'] = options.rust_toolchain_library_path or ''
1787+
1788+
17751789
def configure_v8(o, configs):
17761790
set_configuration_variable(configs, 'v8_enable_v8_checks', release=1, debug=0)
17771791

@@ -2325,6 +2339,7 @@ def make_bin_override():
23252339
'libraries': [],
23262340
'defines': [],
23272341
'cflags': [],
2342+
'conditions': [],
23282343
}
23292344
configurations = {
23302345
'Release': { 'variables': {} },
@@ -2365,6 +2380,7 @@ def make_bin_override():
23652380
configure_static(output)
23662381
configure_inspector(output)
23672382
configure_section_file(output)
2383+
configure_rust(output, configurations)
23682384

23692385
# remove builtins that have been disabled
23702386
if options.without_amaro:
@@ -2387,6 +2403,17 @@ def make_bin_override():
23872403
variables = output['variables']
23882404
del output['variables']
23892405

2406+
# move configurations[*]['variables'] to conditions variables
2407+
config_release_vars = configurations['Release']['variables']
2408+
del configurations['Release']['variables']
2409+
config_debug_vars = configurations['Debug']['variables']
2410+
del configurations['Debug']['variables']
2411+
output['conditions'].append(['build_type=="Release"', {
2412+
'variables': config_release_vars,
2413+
}, {
2414+
'variables': config_debug_vars,
2415+
}])
2416+
23902417
# make_global_settings should be a root level element too
23912418
if 'make_global_settings' in output:
23922419
make_global_settings = output['make_global_settings']
@@ -2406,8 +2433,9 @@ def make_bin_override():
24062433

24072434
print_verbose(output)
24082435

2436+
# Dump as JSON to allow js2c.cc read it as a simple json file.
24092437
write('config.gypi', do_not_edit +
2410-
pprint.pformat(output, indent=2, width=128) + '\n')
2438+
json.dumps(output, indent=2) + '\n')
24112439

24122440
write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
24132441
' '.join([shlex.quote(arg) for arg in original_argv]) + '\n')
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'temporal_capi',
5+
'type': 'none',
6+
'hard_dependency': 1,
7+
'sources': [
8+
'src/calendar.rs',
9+
'src/error.rs',
10+
'src/lib.rs',
11+
'src/plain_date_time.rs',
12+
'src/plain_month_day.rs',
13+
'src/plain_year_month.rs',
14+
'src/time_zone.rs',
15+
'src/duration.rs',
16+
'src/instant.rs',
17+
'src/options.rs',
18+
'src/plain_date.rs',
19+
'src/plain_time.rs',
20+
'src/provider.rs',
21+
'src/zoned_date_time.rs',
22+
],
23+
'direct_dependent_settings': {
24+
'include_dirs': [
25+
'bindings/cpp',
26+
],
27+
},
28+
'link_settings': {
29+
'libraries': [
30+
'<(SHARED_INTERMEDIATE_DIR)/>(cargo_build_mode)/libtemporal_capi.a',
31+
],
32+
},
33+
'actions': [
34+
{
35+
'action_name': 'cargo_build',
36+
'inputs': [
37+
'<@(_sources)',
38+
],
39+
'outputs': [
40+
'<(SHARED_INTERMEDIATE_DIR)/>(cargo_build_mode)/libtemporal_capi.a'
41+
],
42+
'action': [
43+
'cargo',
44+
'rustc',
45+
'>@(cargo_build_flags)',
46+
'--crate-type',
47+
'staticlib',
48+
'--features',
49+
'zoneinfo64',
50+
'--target-dir',
51+
'<(SHARED_INTERMEDIATE_DIR)'
52+
],
53+
}
54+
],
55+
}
56+
]
57+
}

0 commit comments

Comments
 (0)