summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian "sp1rit"​ <sp1rit@disroot.org>2024-11-19 12:49:17 +0100
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2025-01-20 14:06:24 +0530
commit4d4839c6ee73b89f8a6ed394fbfdf498a203d712 (patch)
tree9b9f38d5fdcbc1606532948e01902f0f7a4b3eab
parent91eb6c2289335ade41dd65ad1373c68b9d4ffb14 (diff)
downloadmeson-4d4839c6ee73b89f8a6ed394fbfdf498a203d712.tar.gz
compilers/clike: Speedup cross_compute_int
Expand the expression passed into cross_compute_int using the preprocessor first and then try to evaluate the expanded expression using the host machine compiler and test if the result is valid. Co-authored-by: Charles Brunet <charles.brunet@optelgroup.com>
-rw-r--r--mesonbuild/compilers/mixins/clike.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index a75cd2a81..19a6bb487 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -476,6 +476,21 @@ class CLikeCompiler(Compiler):
if self._compile_int(f'{expression} == {guess}', prefix, env, extra_args, dependencies):
return guess
+ # Try to expand the expression and evaluate it on the build machines compiler
+ if self.language in env.coredata.compilers.build:
+ try:
+ expanded, _ = self.get_define(expression, prefix, env, extra_args, dependencies, False)
+ evaluate_expanded = f'''
+ #include <stdio.h>
+ #include <stdint.h>
+ int main(void) {{ int expression = {expanded}; printf("%d", expression); return 0; }}'''
+ run = env.coredata.compilers.build[self.language].run(evaluate_expanded, env)
+ if run and run.compiled and run.returncode == 0:
+ if self._compile_int(f'{expression} == {run.stdout}', prefix, env, extra_args, dependencies):
+ return int(run.stdout)
+ except mesonlib.EnvironmentException:
+ pass
+
# If no bounds are given, compute them in the limit of int32
maxint = 0x7fffffff
minint = -0x80000000