Skip to content

Commit e213957

Browse files
bsheedy-workDawn LUCI CQ
authored andcommitted
Explicitly list Node architectures
Updates Dawn's NodeJS dependency to explicitly fetch CIPD packages for all supported architectures for an OS instead of relying on ${{platform}}. Users of this dependency are also updated to select the correct copy based on the OS/arch combination at runtime. This is necessary in order to properly support running Node-based tests on OSes that support multiple architectures. Using ${{platform}} when fetching dependencies implicitly assumes that the architecture of the machine fetching dependencies/building is the same as the machine that will run tests. This assumption does not hold true now that we support running tests on Swarming, as Mac in particular prefers to build on arm64 regardless of which architecture is being built for. Bug: 441328362 Change-Id: Ida2786ff421e35effc812d40a83af951ef3dbb48 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/264634 Auto-Submit: Brian Sheedy <[email protected]> Reviewed-by: Yuly Novikov <[email protected]> Commit-Queue: Yuly Novikov <[email protected]>
1 parent 9308754 commit e213957

File tree

3 files changed

+123
-17
lines changed

3 files changed

+123
-17
lines changed

DEPS

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,68 @@ deps = {
390390
'condition': 'dawn_node',
391391
},
392392

393-
# Node binaries, when dawn_node or dawn_wasm is enabled
394-
'third_party/node': {
393+
# Node binaries, when dawn_node or dawn_wasm is enabled. Architectures are
394+
# listed out explicitly instead of using ${{platform}} because the
395+
# architecture that these are fetched on can differ from the architecture that
396+
# tests are ultimately run on, such as x64 vs. ARM64 Mac.
397+
'third_party/node/linux-amd64': {
395398
'packages': [
396399
{
397-
'package': 'infra/3pp/tools/nodejs/${{platform}}',
400+
'package': 'infra/3pp/tools/nodejs/linux-amd64',
398401
'version': Var('dawn_node_version'),
399402
},
400403
],
401-
'condition': 'dawn_node or dawn_wasm',
404+
'condition': 'checkout_linux and (dawn_node or dawn_wasm)',
405+
'dep_type': 'cipd',
406+
},
407+
'third_party/node/linux-arm64': {
408+
'packages': [
409+
{
410+
'package': 'infra/3pp/tools/nodejs/linux-arm64',
411+
'version': Var('dawn_node_version'),
412+
},
413+
],
414+
'condition': 'checkout_linux and (dawn_node or dawn_wasm)',
415+
'dep_type': 'cipd',
416+
},
417+
'third_party/node/mac-amd64': {
418+
'packages': [
419+
{
420+
'package': 'infra/3pp/tools/nodejs/mac-amd64',
421+
'version': Var('dawn_node_version'),
422+
},
423+
],
424+
'condition': 'checkout_mac and (dawn_node or dawn_wasm)',
425+
'dep_type': 'cipd',
426+
},
427+
'third_party/node/mac-arm64': {
428+
'packages': [
429+
{
430+
'package': 'infra/3pp/tools/nodejs/mac-arm64',
431+
'version': Var('dawn_node_version'),
432+
},
433+
],
434+
'condition': 'checkout_mac and (dawn_node or dawn_wasm)',
435+
'dep_type': 'cipd',
436+
},
437+
'third_party/node/windows-amd64': {
438+
'packages': [
439+
{
440+
'package': 'infra/3pp/tools/nodejs/windows-amd64',
441+
'version': Var('dawn_node_version'),
442+
},
443+
],
444+
'condition': 'checkout_win and (dawn_node or dawn_wasm)',
445+
'dep_type': 'cipd',
446+
},
447+
'third_party/node/windows-arm64': {
448+
'packages': [
449+
{
450+
'package': 'infra/3pp/tools/nodejs/windows-arm64',
451+
'version': Var('dawn_node_version'),
452+
},
453+
],
454+
'condition': 'checkout_win and (dawn_node or dawn_wasm)',
402455
'dep_type': 'cipd',
403456
},
404457

scripts/dawn_node_cts/node_helpers.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,56 @@
2828

2929
import functools
3030
import os
31+
import platform
3132
import sys
3233

3334
THIS_DIR = os.path.dirname(__file__)
3435
DAWN_ROOT = os.path.realpath(os.path.join(THIS_DIR, '..', '..'))
35-
NODE_DIR = os.path.join(DAWN_ROOT, 'third_party', 'node')
36+
37+
38+
@functools.cache
39+
def get_node_dir() -> str:
40+
"""Retrieves the directory that NodeJS should be available in."""
41+
cipd_os = get_cipd_compatible_current_os()
42+
cipd_arch = get_cipd_compatible_current_arch()
43+
cipd_platform = f'{cipd_os}-{cipd_arch}'
44+
return os.path.join(DAWN_ROOT, 'third_party', 'node', cipd_platform)
45+
46+
47+
@functools.cache
48+
def get_cipd_compatible_current_os() -> str:
49+
"""Retrieves the current OS name.
50+
51+
The returned string is compatible with CIPD's package naming scheme.
52+
"""
53+
current_platform = sys.platform
54+
if current_platform in ('linux', 'cygwin'):
55+
return 'linux'
56+
if current_platform == 'win32':
57+
return 'windows'
58+
if current_platform == 'darwin':
59+
return 'mac'
60+
raise ValueError(f'Unknown platform {current_platform}')
61+
62+
63+
@functools.cache
64+
def get_cipd_compatible_current_arch() -> str:
65+
"""Retrieves the current architecture.
66+
67+
The returned string is compatible with CIPD's package naming scheme.
68+
"""
69+
native_arm = platform.machine().lower() in ('arm', 'arm64')
70+
# This is necessary for the case of running x86 Python on arm devices via
71+
# an emulator. In this case, platform.machine() will show up as an x86
72+
# processor.
73+
emulated_x86 = 'armv8' in platform.processor().lower()
74+
if native_arm or emulated_x86:
75+
return 'arm64'
76+
77+
native_x86 = platform.machine().lower() in ('x86', 'x86_64', 'amd64')
78+
if native_x86:
79+
return 'amd64'
80+
raise ValueError('Unable to determine architecture')
3681

3782

3883
@functools.cache
@@ -42,12 +87,12 @@ def get_node_path() -> str:
4287
Returns:
4388
A filepath to the standalone node executable.
4489
"""
45-
path = os.path.join(NODE_DIR, 'bin', 'node')
90+
path = os.path.join(get_node_dir(), 'bin', 'node')
4691
if sys.platform == 'win32':
47-
path = os.path.join(NODE_DIR, 'node.exe')
92+
path = os.path.join(get_node_dir(), 'node.exe')
4893
if not os.path.exists(path):
4994
raise RuntimeError(
50-
f'Unable to find the node binary under {NODE_DIR}. Is the '
95+
f'Unable to find the node binary under {get_node_dir()}. Is the '
5196
f'dawn_node gclient variable set?')
5297
return path
5398

@@ -60,18 +105,18 @@ def get_npm_command() -> list[str]:
60105
A list of strings that will run "npm" when run as a command for a
61106
subprocess.
62107
"""
63-
path = os.path.join(NODE_DIR, 'lib', 'node_modules', 'npm', 'bin',
108+
path = os.path.join(get_node_dir(), 'lib', 'node_modules', 'npm', 'bin',
64109
'npm-cli.js')
65110
if sys.platform == 'win32':
66-
path = os.path.join(NODE_DIR, 'node_modules', 'npm', 'bin',
111+
path = os.path.join(get_node_dir(), 'node_modules', 'npm', 'bin',
67112
'npm-cli.js')
68113
if not os.path.exists(path):
69114
raise RuntimeError(
70-
f'Unable to find the npm-cli.js file under {NODE_DIR}. Is the '
115+
f'Unable to find the npm-cli.js file under {get_node_dir()}. Is the '
71116
f'dawn_node gclient variable set?')
72117
cmd = [
73118
get_node_path(),
74-
os.path.join(NODE_DIR, path),
119+
os.path.join(get_node_dir(), path),
75120
]
76121
return cmd
77122

tools/src/fileutils/paths.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ func NodePath(fsReader oswrapper.FilesystemReader) string {
100100
node := filepath.Join(dawnRoot, "third_party", "node")
101101
if info, err := fsReader.Stat(node); err == nil && info.IsDir() {
102102
path := ""
103-
switch runtime.GOOS { // See `go tool dist list`
104-
case "windows":
105-
path = filepath.Join(node, "node.exe")
106-
default:
107-
path = filepath.Join(node, "bin", "node")
103+
switch fmt.Sprintf("%v/%v", runtime.GOOS, runtime.GOARCH) { // See `go tool dist list`
104+
case "darwin/amd64":
105+
path = filepath.Join(node, "mac-amd64", "bin", "node")
106+
case "darwin/arm64":
107+
path = filepath.Join(node, "mac-arm64", "bin", "node")
108+
case "linux/amd64":
109+
path = filepath.Join(node, "linux-amd64", "bin", "node")
110+
case "linux/arm64":
111+
path = filepath.Join(node, "linux-arm64", "bin", "node")
112+
case "windows/amd64":
113+
path = filepath.Join(node, "windows-amd64", "node.exe")
114+
case "windows/arm64":
115+
path = filepath.Join(node, "windows-arm64", "node.exe")
108116
}
109117
if _, err := fsReader.Stat(path); err == nil {
110118
return path

0 commit comments

Comments
 (0)