Skip to content

Commit d6527d9

Browse files
committed
Fixes to get unit tests working for ARM64 and Visual Studio 2022 Preview
1 parent 5402fc9 commit d6527d9

8 files changed

+59
-36
lines changed

em++.py

+5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
# University of Illinois/NCSA Open Source License. Both these licenses can be
55
# found in the LICENSE file.
66

7+
import os
78
import sys
9+
10+
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
11+
sys.path.append(__rootpath__)
12+
813
import emcc
914

1015
emcc.run_via_emxx = True

emar.py

+5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
"""Wrapper scripte around `llvm-ar`.
88
"""
99

10+
import os
1011
import sys
12+
13+
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
14+
sys.path.append(__rootpath__)
15+
1116
from tools import shared
1217

1318
cmd = [shared.LLVM_AR] + sys.argv[1:]

embuilder.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
import argparse
1616
import logging
1717
import sys
18+
import os
1819
import time
1920
from contextlib import contextmanager
2021

22+
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
23+
sys.path.append(__rootpath__)
24+
2125
from tools import cache
2226
from tools import shared
2327
from tools import system_libs

emcc.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020
slows down compilation).
2121
"""
2222

23+
import os
24+
import sys
25+
26+
__rootpath__ = os.path.dirname(os.path.abspath(__file__))
27+
sys.path.append(__rootpath__)
28+
2329
from tools.toolchain_profiler import ToolchainProfiler
2430

2531
import base64
2632
import glob
2733
import hashlib
2834
import json
2935
import logging
30-
import os
3136
import re
3237
import shlex
3338
import shutil
3439
import stat
35-
import sys
3640
import time
3741
import tarfile
3842
from enum import Enum, unique, auto

test/clang_native.py

+34-32
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# University of Illinois/NCSA Open Source License. Both these licenses can be
44
# found in the LICENSE file.
55

6+
import json
67
import logging
78
import os
89
import platform
10+
import subprocess
911
import sys
1012
from tools.shared import PIPE, run_process, CLANG_CC, CLANG_CXX
1113
from tools.utils import MACOS, WINDOWS, path_from_root
@@ -19,6 +21,7 @@ def get_native_triple():
1921
'arm64': 'arm64',
2022
'x86_64': 'x86_64',
2123
'AMD64': 'x86_64',
24+
'ARM64': 'arm64',
2225
}[platform.machine()]
2326
OS = {
2427
'linux': 'linux',
@@ -66,19 +69,14 @@ def get_clang_native_env():
6669
CACHED_CLANG_NATIVE_ENV = env
6770
return env
6871

69-
# Guess where VS2015 is installed (VSINSTALLDIR env. var in VS2015 X64 Command Prompt)
70-
if 'VSINSTALLDIR' in env:
71-
visual_studio_path = env['VSINSTALLDIR']
72-
elif 'VS140COMNTOOLS' in env:
73-
visual_studio_path = os.path.normpath(os.path.join(env['VS140COMNTOOLS'], '../..'))
74-
elif 'ProgramFiles(x86)' in env:
75-
visual_studio_path = os.path.normpath(os.path.join(env['ProgramFiles(x86)'], 'Microsoft Visual Studio 14.0'))
76-
elif 'ProgramFiles' in env:
77-
visual_studio_path = os.path.normpath(os.path.join(env['ProgramFiles'], 'Microsoft Visual Studio 14.0'))
78-
else:
79-
visual_studio_path = 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0'
72+
# Guess where Visual Studio is installed
73+
for version in range(17, 13, -1):
74+
visual_studio_path = vswhere(version)
75+
if visual_studio_path:
76+
break
77+
8078
if not os.path.isdir(visual_studio_path):
81-
raise Exception('Visual Studio 2015 was not found in "' + visual_studio_path + '"! Run in Visual Studio X64 command prompt to avoid the need to autoguess this location (or set VSINSTALLDIR env var).')
79+
raise Exception('Visual Studio was not found in "' + visual_studio_path + '"! Run in Visual Studio X64 command prompt to avoid the need to autoguess this location (or set VSINSTALLDIR env var).')
8280

8381
# Guess where Program Files (x86) is located
8482
if 'ProgramFiles(x86)' in env:
@@ -92,14 +90,6 @@ def get_clang_native_env():
9290
else:
9391
raise Exception('Unable to detect Program files directory for native Visual Studio build!')
9492

95-
# Guess where Windows 8.1 SDK is located
96-
if 'WindowsSdkDir' in env:
97-
windows8_sdk_dir = env['WindowsSdkDir']
98-
else:
99-
windows8_sdk_dir = os.path.join(prog_files_x86, 'Windows Kits', '8.1')
100-
if not os.path.isdir(windows8_sdk_dir):
101-
raise Exception('Windows 8.1 SDK was not found in "' + windows8_sdk_dir + '"! Run in Visual Studio command prompt to avoid the need to autoguess this location (or set WindowsSdkDir env var).')
102-
10393
# Guess where Windows 10 SDK is located
10494
if os.path.isdir(os.path.join(prog_files_x86, 'Windows Kits', '10')):
10595
windows10_sdk_dir = os.path.join(prog_files_x86, 'Windows Kits', '10')
@@ -118,27 +108,39 @@ def append_item(key, item):
118108
else:
119109
env[key] = env[key] + ';' + item
120110

121-
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'INCLUDE'))
122-
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'INCLUDE'))
111+
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'include'))
112+
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'atlmfc', 'include'))
123113
append_item('INCLUDE', os.path.join(windows10_sdk_dir, 'include', windows10sdk_kit_version_name, 'ucrt'))
124-
# append_item('INCLUDE', 'C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um') # VS2015 X64 command prompt has this, but not needed for Emscripten
125-
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'INCLUDE'))
126-
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'shared'))
127-
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'um'))
128-
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'winrt'))
129-
logger.debug('VS2015 native build INCLUDE: ' + env['INCLUDE'])
114+
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'atlmfc', 'include'))
115+
# TODO: Get this path form the environment.
116+
append_item('INCLUDE', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.35.32213\\include')
117+
logger.debug('Visual Studio native build INCLUDE: ' + env['INCLUDE'])
118+
119+
#
130120

131121
append_item('LIB', os.path.join(env['VCINSTALLDIR'], 'LIB', 'amd64'))
132122
append_item('LIB', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'LIB', 'amd64'))
133123
append_item('LIB', os.path.join(windows10_sdk_dir, 'lib', windows10sdk_kit_version_name, 'ucrt', 'x64'))
134-
# append_item('LIB', 'C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\lib\\um\\x64') # VS2015 X64 command prompt has this, but not needed for Emscripten
135-
append_item('LIB', os.path.join(windows8_sdk_dir, 'lib', 'winv6.3', 'um', 'x64'))
136-
logger.debug('VS2015 native build LIB: ' + env['LIB'])
124+
logger.debug('Visual Studio native build LIB: ' + env['LIB'])
137125

138126
env['PATH'] = env['PATH'] + ';' + os.path.join(env['VCINSTALLDIR'], 'BIN')
139-
logger.debug('VS2015 native build PATH: ' + env['PATH'])
127+
logger.debug('Visual Studio native build PATH: ' + env['PATH'])
140128

141129
# Current configuration above is all Visual Studio -specific, so on non-Windowses, no action needed.
142130

143131
CACHED_CLANG_NATIVE_ENV = env
144132
return env
133+
134+
135+
def vswhere(version):
136+
try:
137+
program_files = os.getenv('ProgramFiles(x86)')
138+
if not program_files:
139+
program_files = os.environ['ProgramFiles']
140+
vswhere_path = os.path.join(program_files, 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
141+
result = subprocess.check_output([vswhere_path, '-latest', '-prerelease', '-version', '[%s.0,%s.0)' % (version, version + 1), '-products', '*', '-property', 'installationPath', '-format', 'json'])
142+
output = json.loads(result)
143+
144+
return str(output[0]['installationPath'])
145+
except Exception:
146+
return ''

test/runner.py

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3535
sys.path.append(__rootpath__)
36+
__testpath__ = os.path.dirname(os.path.abspath(__file__))
37+
sys.path.append(__testpath__)
3638

3739
import jsrun
3840
import parallel_testsuite

test/test_sanity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from tools import ports
2626

2727
SANITY_FILE = cache.get_path('sanity.txt')
28-
commands = [[EMCC], [path_from_root('test/runner'), 'blahblah']]
28+
commands = [[EMCC], [path_from_root('test/runner.bat'), 'blahblah']]
2929
expected_llvm_version = str(shared.EXPECTED_LLVM_VERSION) + '.0.0'
3030

3131

@@ -720,7 +720,7 @@ def test_embuilder_wasm_backend(self):
720720
def test_binaryen_version(self):
721721
restore_and_set_up()
722722
with open(EM_CONFIG, 'a') as f:
723-
f.write('\nBINARYEN_ROOT = "' + self.in_dir('fake') + '"')
723+
f.write('\nBINARYEN_ROOT = "' + self.in_dir('fake').replace('\\', '/') + '"')
724724

725725
make_fake_tool(self.in_dir('fake', 'bin', 'wasm-opt'), 'foo')
726726
self.check_working([EMCC, test_file('hello_world.c')], 'error parsing binaryen version (wasm-opt version foo). Please check your binaryen installation')

tools/shared.py

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def run_process(cmd, check=True, input=None, *args, **kw):
111111
sys.stderr.flush()
112112
kw.setdefault('universal_newlines', True)
113113
kw.setdefault('encoding', 'utf-8')
114+
114115
ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
115116
debug_text = '%sexecuted %s' % ('successfully ' if check else '', shlex_join(cmd))
116117
logger.debug(debug_text)

0 commit comments

Comments
 (0)