Skip to content

Commit 9ba26c8

Browse files
committed
Add autoconfig of GCC/Clang arch flags; DMOJ#303
1 parent 6435763 commit 9ba26c8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

.arm.test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313

1414
def main():
15-
judgeenv.env['runtime'] = {
16-
'clang_target_arch': None, # Clang can't autodetect march=native
17-
}
18-
judgeenv.env['extra_fs'] = {};
15+
judgeenv.env['runtime'] = {}
16+
judgeenv.env['extra_fs'] = {}
1917

2018
logging.basicConfig(level=logging.INFO)
2119

dmoj/executors/gcc_executor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ def get_march_flag(cls):
100100
def get_version_flags(cls, command):
101101
return ['-dumpversion']
102102

103+
@classmethod
104+
def autoconfig_run_test(cls, result):
105+
# Some versions of GCC/Clang (like those in Raspbian or ARM64 Debian)
106+
# can't autodetect the CPU, in which case our unconditional passing of
107+
# -march=native breaks. Here we try to see if -march=native works, and
108+
# if not fall back to a generic (slow) build.
109+
for target in ['native', None]:
110+
result[cls.arch] = target
111+
executor = type('Executor', (cls,), {'runtime_dict': result})
112+
executor.__module__ = cls.__module__
113+
errors = []
114+
success = executor.run_self_test(output=False, error_callback=errors.append)
115+
if success:
116+
message = 'Using %s (%s target)' % (result[cls.command], target or 'generic')
117+
# Don't pollute the YAML in the default case
118+
if target == 'native':
119+
del result[cls.arch]
120+
return result, success, message, None
121+
return result, success, 'Failed self-test', '\n'.join(errors)
122+
103123
@classmethod
104124
def autoconfig(cls):
105125
return super(GCCExecutor, cls).autoconfig()

0 commit comments

Comments
 (0)