(env, build_platform, target_triple, build_env, build_options)
| 65 | |
| 66 | |
| 67 | def add_target_env(env, build_platform, target_triple, build_env, build_options): |
| 68 | add_env_common(env) |
| 69 | |
| 70 | settings = get_target_settings(TARGETS_CONFIG, target_triple) |
| 71 | |
| 72 | env["TOOLCHAIN"] = "llvm" |
| 73 | env["HOST_CC"] = settings["host_cc"] |
| 74 | env["HOST_CXX"] = settings["host_cxx"] |
| 75 | env["CC"] = settings["target_cc"] |
| 76 | # We always set CXX, otherwise a build could bypass our toolchain |
| 77 | # accidentally, e.g., on macOS where `g++` links to the system clang. |
| 78 | env["CXX"] = settings["target_cxx"] |
| 79 | |
| 80 | if settings.get("bolt_capable"): |
| 81 | env["BOLT_CAPABLE"] = "1" |
| 82 | |
| 83 | env["PYBUILD_PLATFORM"] = build_platform |
| 84 | env["TOOLS_PATH"] = build_env.tools_path |
| 85 | |
| 86 | if "debug" in build_options: |
| 87 | extra_target_cflags = ["-O0"] |
| 88 | else: |
| 89 | extra_target_cflags = ["-O3"] |
| 90 | extra_target_cflags += list(settings.get("target_cflags", [])) |
| 91 | extra_target_ldflags = list(settings.get("target_ldflags", [])) |
| 92 | extra_host_cflags = [] |
| 93 | extra_host_ldflags = [] |
| 94 | |
| 95 | # Add compiler-rt for aarch64-musl to resolve missing builtins |
| 96 | if target_triple == "aarch64-unknown-linux-musl": |
| 97 | extra_target_cflags.append("--rtlib=compiler-rt") |
| 98 | extra_target_ldflags.append("--rtlib=compiler-rt") |
| 99 | |
| 100 | if build_platform.startswith("linux_"): |
| 101 | machine = platform.machine() |
| 102 | |
| 103 | # arm64 allows building for Linux on a macOS host using Docker |
| 104 | if machine == "aarch64" or machine == "arm64": |
| 105 | env["BUILD_TRIPLE"] = "aarch64-unknown-linux-gnu" |
| 106 | env["TARGET_TRIPLE"] = target_triple |
| 107 | elif machine == "x86_64": |
| 108 | env["BUILD_TRIPLE"] = "x86_64-unknown-linux-gnu" |
| 109 | env["TARGET_TRIPLE"] = ( |
| 110 | target_triple.replace("x86_64_v2-", "x86_64-") |
| 111 | .replace("x86_64_v3-", "x86_64-") |
| 112 | .replace("x86_64_v4-", "x86_64-") |
| 113 | ) |
| 114 | else: |
| 115 | raise Exception("unhandled Linux machine value: %s" % machine) |
| 116 | |
| 117 | # This will make x86_64_v2, etc count as cross-compiling. This is |
| 118 | # semantically correct, since the current machine may not support |
| 119 | # instructions on the target machine type. |
| 120 | if env["BUILD_TRIPLE"] != target_triple or target_triple.endswith( |
| 121 | "-unknown-linux-musl" |
| 122 | ): |
| 123 | env["CROSS_COMPILING"] = "1" |
| 124 |
no test coverage detected