Skip to content
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

always resolve emnapi paths #56

Merged
merged 4 commits into from
Oct 20, 2024
Merged
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
13 changes: 8 additions & 5 deletions mesonbuild/modules/node-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def __init__(self, interpreter: 'Interpreter') -> None:
self.source_root: Path = Path(interpreter.environment.get_source_dir())
self.load_node_process()
self.download_headers()
if 'cpp' in self.interpreter.environment.coredata.compilers.host:
self.load_node_addon_api_package()
if self.interpreter.environment.machines.host.system == 'emscripten':
self.load_emnapi_package()
self.methods.update({
'extension_module': self.extension_module_method,
'test': self.test_method,
Expand All @@ -142,10 +146,12 @@ def load_node_process(self) -> None:
def load_node_addon_api_package(self) -> None:
if self.node_addon_api_package is None:
self.node_addon_api_package = self.parse_node_json_output('require("node-addon-api")')
mlog.log('node-addon-api:', mlog.bold(self.node_addon_api_package['include'].strip('\"')))

def load_emnapi_package(self) -> None:
if self.emnapi_package is None:
self.emnapi_package = self.parse_node_json_output('require("emnapi")')
mlog.log('emnapi:', mlog.bold(str([str(p) for p in self.emnapi_include_dirs(self.source_root)])))

def construct_swig_options(self, opts: 'NodeAPIOptions') -> T.List[str]:
if opts['swig']:
Expand Down Expand Up @@ -256,21 +262,18 @@ def relativize(self, p: T.Union[str, Path], source_dir: Path) -> Path:
def resolve(self, p: T.Union[str, Path]) -> Path:
r: Path = p if isinstance(p, Path) else Path(p)
if r.is_absolute():
return r
return self.source_root / r
return r.resolve()
return (self.source_root / r).resolve()

def emnapi_sources(self, source_root: Path) -> T.List[Path]:
self.load_emnapi_package()
sources: T.List[str] = self.emnapi_package['sources']
return [self.relativize(self.resolve(d), source_root) for d in sources]

def emnapi_include_dirs(self, source_root: Path) -> T.List[Path]:
self.load_emnapi_package()
inc_dirs: T.List[str] = [self.emnapi_package['include_dir']]
return [self.relativize(self.resolve(d), source_root) for d in inc_dirs]

def emnapi_js_library(self, source_root: Path) -> Path:
self.load_emnapi_package()
js_lib: str = self.emnapi_package['js_library']
return Path(js_lib)

Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/1 hello_world/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'hello_world.cc' ],
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/2 subdir/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'src/hello_world.cc' ],
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/3 async/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

thread_dep = dependency('threads')

addon = napi.extension_module(
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/4 legacy cjs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'hello_world.cc' ],
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/5 plain c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'hello_c_world.c' ],
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/6 no exceptions/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ project(
default_options: ['buildtype=release']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'hello_world.cc' ],
Expand Down
4 changes: 2 additions & 2 deletions test cases/node-api/7 environments/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

addon = napi.extension_module(
'hello_world',
[ 'hello_world.cc' ],
Expand Down
3 changes: 1 addition & 2 deletions test cases/node-api/8 swig/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ project(
['c', 'cpp']
)

napi = import('node-api')

run_command(['npm', '--prefix', meson.global_source_root(), 'install'], check: true)

napi = import('node-api')

thread_dep = dependency('threads')
addon = napi.extension_module(
Expand Down
Loading