Skip to content

Commit

Permalink
Add global option --arch
Browse files Browse the repository at this point in the history
Allows to specify a custom architecture target.
Useful for arm64-based Apple computers, until
all used native libraries are released for arm64.

Example usage:
  mx --arch amd64 ...
  • Loading branch information
errikos committed Oct 4, 2021
1 parent 91d7a51 commit 15fa6b7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
29 changes: 17 additions & 12 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def __init__(self, parents=None):
"projects and store it in the given <file>. If <file> is 'default', the compilation database will "
"be stored in the parent directory of the repository containing the primary suite. This option "
"can also be configured using the MX_COMPDB environment variable. Use --compdb none to disable.")
self.add_argument('--arch', action='store', dest='arch', help='force use the specified architecture', choices=['arm64', 'aarch64', 'amd64', 'sparcv9'])

if not is_windows():
# Time outs are (currently) implemented with Unix specific functionality
Expand Down Expand Up @@ -679,6 +680,9 @@ def _parse_cmd_line(self, opts, firstParse):
except IOError as e:
abort('Error opening {} specified by --exec-log: {}'.format(opts.exec_log, e))

if opts.arch and opts.arch != get_arch():
warn('overriding detected architecture ({}) with {}'.format(get_arch(), opts.arch))

else:
parser = ArgParser(parents=[self])
parser.add_argument('commandAndArgs', nargs=REMAINDER, metavar='command args...')
Expand Down Expand Up @@ -1735,7 +1739,7 @@ def _make_config(platformDependent=False, jdkDependent=None):
if release not in jdk_releases:
jdk_releases.append(release)
if platformDependent:
config.append(get_os() + '-' + get_arch())
config.append(get_os() + '-' + get_effective_arch())
if jdk_releases:
config.append('jdk' + '+'.join(jdk_releases))
config = '-'.join(config)
Expand Down Expand Up @@ -1790,7 +1794,7 @@ def get_output_root(self, platformDependent=False, jdkDependent=None):
else:
self._outputRoot = self.getMxCompatibility().getSuiteOutputRoot(self)
if platformDependent:
return os.path.join(self._outputRoot, get_os() + '-' + get_arch())
return os.path.join(self._outputRoot, get_os() + '-' + get_effective_arch())
else:
return self._outputRoot

Expand Down Expand Up @@ -2215,7 +2219,7 @@ def _init_imports(self):
import_dict = entry
imported_suite_name = import_dict.get('name', '<unknown>')
if import_dict.get('ignore', False):
log("Ignoring '{}' on your platform ({}/{})".format(imported_suite_name, get_os(), get_arch()))
log("Ignoring '{}' on your platform ({}/{})".format(imported_suite_name, get_os(), get_effective_arch()))
continue
if import_dict.get('dynamic', False) and imported_suite_name not in (name for name, _ in get_dynamic_imports()):
continue
Expand Down Expand Up @@ -2337,13 +2341,13 @@ def _pop_os_arch(attrs, context):
os_key = '<others>'
os_attrs = os_arch.pop(os_key, None)
if os_attrs:
arch_attrs = os_attrs.pop(get_arch(), None)
arch_attrs = os_attrs.pop(get_effective_arch(), None)
if not arch_attrs:
arch_attrs = os_attrs.pop('<others>', None)
if arch_attrs:
return arch_attrs
else:
warn("No platform-specific definition is available for {} for your architecture ({})".format(context, get_arch()))
warn("No platform-specific definition is available for {} for your architecture ({})".format(context, get_effective_arch()))
else:
warn("No platform-specific definition is available for {} for your OS ({})".format(context, get_os()))
return None
Expand Down Expand Up @@ -3837,6 +3841,12 @@ def _separatedCygpathW2U(p):
return p
return os.pathsep.join(map(_cygpathW2U, p.split(';')))

def get_effective_arch():
if _opts.arch is not None:
return _opts.arch

return get_effective_arch()

def get_arch():
machine = platform.uname()[4]
if machine in ['aarch64']:
Expand All @@ -3853,14 +3863,9 @@ def get_arch():
except OSError:
# sysctl is not available
pass
if machine == 'arm64' and is_darwin():
# temporary workaround for arm64 (aarch64) based macOS systems (e.g. M1 processor)
# some libraries don't have a macOS arm64 build yet (e.g. ASYNC_PROFILER),
# but they can run as amd64 with Rosetta2
return 'amd64'
abort('unknown or unsupported architecture: os=' + get_os() + ', machine=' + machine)

mx_subst.results_substitutions.register_no_arg('arch', get_arch)
mx_subst.results_substitutions.register_no_arg('arch', get_effective_arch)

def vc_system(kind, abortOnError=True):
for vc in _vc_systems:
Expand Down Expand Up @@ -5384,7 +5389,7 @@ def default_filename(self):

@classmethod
def platformName(cls):
return '{os}_{arch}'.format(os=get_os(), arch=get_arch())
return '{os}_{arch}'.format(os=get_os(), arch=get_effective_arch())

"""
Provide remoteName of distribution.
Expand Down
4 changes: 2 additions & 2 deletions mx_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def libraryPath(self):
async_profiler_lib = mx.library("ASYNC_PROFILER_{}".format(self.version()))
if not async_profiler_lib.is_available():
raise mx.abort("'--profiler {}' is not supported on '{}/{}' because the '{}' library is not available."
.format(self.name(), mx.get_os(), mx.get_arch(), async_profiler_lib.name))
.format(self.name(), mx.get_os(), mx.get_effective_arch(), async_profiler_lib.name))

libraryDirectory = async_profiler_lib.get_path(True)
innerDir = [f for f in os.listdir(libraryDirectory) if os.path.isdir(os.path.join(libraryDirectory, f))][0]
Expand Down Expand Up @@ -2259,7 +2259,7 @@ def buildFlags(self):
return ""

def machineArch(self):
return mx.get_arch()
return mx.get_effective_arch()

def machinePlatform(self):
return platform.platform()
Expand Down
2 changes: 1 addition & 1 deletion mx_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CMakeNinjaBuildTask(mx_native.NinjaBuildTask):
def __init__(self, args, project, *otherargs, **kwargs):
super(CMakeNinjaBuildTask, self).__init__(args, project, *otherargs, **kwargs)
self._cmake_config_file = os.path.join(project.suite.get_mx_output_dir(), 'cmakeConfig',
mx.get_os() + '-' + mx.get_arch() if project.isPlatformDependent() else '',
mx.get_os() + '-' + mx.get_effective_arch() if project.isPlatformDependent() else '',
type(project).__name__,
project._extra_artifact_discriminant(),
self.name)
Expand Down
2 changes: 1 addition & 1 deletion mx_fetchjdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class _JdkBinary(object):
def __init__(self, jdk_id, version, filename, url, source):
self._jdk_id = jdk_id
self._version = version
platform = mx.get_os() + '-' + mx.get_arch()
platform = mx.get_os() + '-' + mx.get_effective_arch()
keywords = {'version': version, 'platform': platform}
self._filename = _instantiate(filename, keywords, source)
keywords['filename'] = self._filename
Expand Down
2 changes: 1 addition & 1 deletion mx_javamodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def __exit__(self, exc_type, exc_value, traceback):
# attribute of module-info.class.
target_os = mx.get_os()
target_os = 'macos' if target_os == 'darwin' else target_os
target_arch = mx.get_arch()
target_arch = mx.get_effective_arch()
jmod_args.append('--target-platform={}-{}'.format(target_os, target_arch))
if exists(jdk_jmod):
with ZipFile(jdk_jmod, 'r') as zf:
Expand Down
14 changes: 7 additions & 7 deletions mx_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def target(self):

@property
def is_native(self):
return self.target_arch == mx.get_arch()
return self.target_arch == mx.get_effective_arch()

@property
def is_available(self):
Expand Down Expand Up @@ -185,8 +185,8 @@ def __init__(self, suite, name, subDir, srcDirs, deps, workingSets, d, **kwargs)
if 'multiarch' in kwargs:
multiarch = mx.Suite._pop_list(kwargs, 'multiarch', context)
self.multiarch = list(set(mx_subst.results_substitutions.substitute(arch) for arch in multiarch))
if mx.get_arch() not in self.multiarch:
mx.abort('"multiarch" must contain the host architecture "{}"'.format(mx.get_arch()), context)
if mx.get_effective_arch() not in self.multiarch:
mx.abort('"multiarch" must contain the host architecture "{}"'.format(mx.get_effective_arch()), context)
else:
self.multiarch = []
super(MultiarchProject, self).__init__(suite, name, subDir, srcDirs, deps, workingSets, d, **kwargs)
Expand All @@ -210,14 +210,14 @@ def newestOutput(self):

return MultiarchBuildTask(self, args)
else:
return self._build_task(mx.get_arch(), args)
return self._build_task(mx.get_effective_arch(), args)

@abc.abstractmethod
def _build_task(self, target_arch, args):
""":rtype: TargetArchBuildTask"""

def getArchivableResults(self, use_relpath=True, single=False):
for target_arch in self.multiarch if self._use_multiarch else [mx.get_arch()]:
for target_arch in self.multiarch if self._use_multiarch else [mx.get_effective_arch()]:
toolchain = _Toolchain.for_(target_arch)
target_arch_path = toolchain.target if self.multiarch else ''
if toolchain.is_native or not single:
Expand Down Expand Up @@ -392,7 +392,7 @@ class NinjaBuildTask(TargetArchBuildTask):
require special consideration.
"""

def __init__(self, args, project, target_arch=mx.get_arch(), ninja_targets=None):
def __init__(self, args, project, target_arch=mx.get_effective_arch(), ninja_targets=None):
super(NinjaBuildTask, self).__init__(args, project, target_arch)
self._reason = None
self._manifest = mx.join(self.out_dir, Ninja.default_manifest)
Expand Down Expand Up @@ -656,7 +656,7 @@ def __init__(self, suite, name, subDir, srcDirs, deps, workingSets, d, kind, **k

self.include_dirs = [include_dir]
if kind == 'static_lib':
self.libs = [mx.join(self.out_dir, mx.get_arch(), self._target)]
self.libs = [mx.join(self.out_dir, mx.get_effective_arch(), self._target)]

@property
def _target(self):
Expand Down

0 comments on commit 15fa6b7

Please sign in to comment.