Skip to content
Closed
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
66 changes: 34 additions & 32 deletions test/clang_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

import json
import logging
import os
import platform
import subprocess
import sys
from tools.shared import PIPE, run_process, CLANG_CC, CLANG_CXX
from tools.utils import MACOS, WINDOWS, path_from_root
Expand All @@ -19,6 +21,7 @@ def get_native_triple():
'arm64': 'arm64',
'x86_64': 'x86_64',
'AMD64': 'x86_64',
'ARM64': 'arm64',
}[platform.machine()]
OS = {
'linux': 'linux',
Expand Down Expand Up @@ -66,19 +69,14 @@ def get_clang_native_env():
CACHED_CLANG_NATIVE_ENV = env
return env

# Guess where VS2015 is installed (VSINSTALLDIR env. var in VS2015 X64 Command Prompt)
if 'VSINSTALLDIR' in env:
visual_studio_path = env['VSINSTALLDIR']
elif 'VS140COMNTOOLS' in env:
visual_studio_path = os.path.normpath(os.path.join(env['VS140COMNTOOLS'], '../..'))
elif 'ProgramFiles(x86)' in env:
visual_studio_path = os.path.normpath(os.path.join(env['ProgramFiles(x86)'], 'Microsoft Visual Studio 14.0'))
elif 'ProgramFiles' in env:
visual_studio_path = os.path.normpath(os.path.join(env['ProgramFiles'], 'Microsoft Visual Studio 14.0'))
else:
visual_studio_path = 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0'
# Guess where Visual Studio is installed
for version in range(17, 13, -1):
visual_studio_path = vswhere(version)
if visual_studio_path:
break

if not os.path.isdir(visual_studio_path):
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).')
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).')

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

# Guess where Windows 8.1 SDK is located
if 'WindowsSdkDir' in env:
windows8_sdk_dir = env['WindowsSdkDir']
else:
windows8_sdk_dir = os.path.join(prog_files_x86, 'Windows Kits', '8.1')
if not os.path.isdir(windows8_sdk_dir):
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).')

# Guess where Windows 10 SDK is located
if os.path.isdir(os.path.join(prog_files_x86, 'Windows Kits', '10')):
windows10_sdk_dir = os.path.join(prog_files_x86, 'Windows Kits', '10')
Expand All @@ -118,27 +108,39 @@ def append_item(key, item):
else:
env[key] = env[key] + ';' + item

append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'INCLUDE'))
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'INCLUDE'))
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'include'))
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'atlmfc', 'include'))
append_item('INCLUDE', os.path.join(windows10_sdk_dir, 'include', windows10sdk_kit_version_name, 'ucrt'))
# 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
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'INCLUDE'))
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'shared'))
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'um'))
append_item('INCLUDE', os.path.join(windows8_sdk_dir, 'include', 'winrt'))
logger.debug('VS2015 native build INCLUDE: ' + env['INCLUDE'])
append_item('INCLUDE', os.path.join(env['VCINSTALLDIR'], 'atlmfc', 'include'))
# TODO: Get this path form the environment.
append_item('INCLUDE', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.35.32213\\include')
logger.debug('Visual Studio native build INCLUDE: ' + env['INCLUDE'])

#

append_item('LIB', os.path.join(env['VCINSTALLDIR'], 'LIB', 'amd64'))
append_item('LIB', os.path.join(env['VCINSTALLDIR'], 'ATLMFC', 'LIB', 'amd64'))
append_item('LIB', os.path.join(windows10_sdk_dir, 'lib', windows10sdk_kit_version_name, 'ucrt', 'x64'))
# 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
append_item('LIB', os.path.join(windows8_sdk_dir, 'lib', 'winv6.3', 'um', 'x64'))
logger.debug('VS2015 native build LIB: ' + env['LIB'])
logger.debug('Visual Studio native build LIB: ' + env['LIB'])

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

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

CACHED_CLANG_NATIVE_ENV = env
return env


def vswhere(version):
try:
program_files = os.getenv('ProgramFiles(x86)')
if not program_files:
program_files = os.environ['ProgramFiles']
vswhere_path = os.path.join(program_files, 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
result = subprocess.check_output([vswhere_path, '-latest', '-prerelease', '-version', '[%s.0,%s.0)' % (version, version + 1), '-products', '*', '-property', 'installationPath', '-format', 'json'])
output = json.loads(result)

return str(output[0]['installationPath'])
except Exception:
return ''
2 changes: 1 addition & 1 deletion test/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def test_embuilder_external_ports_options(self):
def test_binaryen_version(self):
restore_and_set_up()
with open(EM_CONFIG, 'a') as f:
f.write('\nBINARYEN_ROOT = "' + self.in_dir('fake') + '"')
f.write('\nBINARYEN_ROOT = "' + self.in_dir('fake').replace('\\', '/') + '"')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do add an r to the start on the string here instead? e.g. f.write('\nBINARYEN_ROOT = r"' + self.in_dir('fake') + '"')


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