Skip to content

Commit 937d772

Browse files
committed
pipeline: Run proper cross compile host
The build-using-self script was always using macos arm64 as a cross compile host. Modify the build-using-self's cross compile host to use x86_64 when on ARM, arm64 when on x86_64, and raise an exception when an any other architecture.
1 parent 71ab073 commit 937d772

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

Diff for: Utilities/build-using-self

+32-18
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ logging.basicConfig(
4747
REPO_ROOT_PATH = pathlib.Path(__file__).parent.parent.resolve()
4848

4949

50+
class UnsupportedArchitecture(Exception):
51+
52+
pass
53+
54+
5055
def get_arguments() -> argparse.Namespace:
5156
parser = argparse.ArgumentParser(
5257
formatter_class=argparse.ArgumentDefaultsHelpFormatter
@@ -89,7 +94,7 @@ def get_swiftpm_bin_dir(config: Configuration) -> pathlib.Path:
8994

9095

9196
def is_on_darwin() -> bool:
92-
return platform.uname().system == "Darwin"
97+
return platform.system() == "Darwin"
9398

9499

95100
def set_environment(*, swiftpm_bin_dir: pathlib.Path,) -> None:
@@ -107,22 +112,30 @@ def set_environment(*, swiftpm_bin_dir: pathlib.Path,) -> None:
107112

108113

109114
def run_bootstrap(swiftpm_bin_dir: pathlib.Path) -> None:
110-
if is_on_darwin():
111-
logging.info("Current working directory is %s", pathlib.Path.cwd())
112-
logging.info("Bootstrapping with the XCBuild codepath...")
113-
call(
114-
[
115-
REPO_ROOT_PATH / "Utilities" / "bootstrap",
116-
"build",
117-
"--release",
118-
"--verbose",
119-
"--cross-compile-hosts",
120-
"macosx-arm64",
121-
"--skip-cmake-bootstrap",
122-
"--swift-build-path",
123-
(swiftpm_bin_dir / "swift-build").resolve(),
124-
],
125-
)
115+
logging.info("Current working directory is %s", pathlib.Path.cwd())
116+
logging.info("Bootstrapping with the XCBuild codepath...")
117+
cross_compile_arch: str
118+
arch = platform.machine()
119+
if arch == "arm64":
120+
cross_compile_arch = "x86_64"
121+
elif arch == "x86_64":
122+
cross_compile_arch = "arm64"
123+
else:
124+
raise UnsupportedArchitecture(f"Architecture {arch} is not supported.")
125+
126+
call(
127+
[
128+
REPO_ROOT_PATH / "Utilities" / "bootstrap",
129+
"build",
130+
"--release",
131+
"--verbose",
132+
"--cross-compile-hosts",
133+
f"macosx-{cross_compile_arch}",
134+
"--skip-cmake-bootstrap",
135+
"--swift-build-path",
136+
(swiftpm_bin_dir / "swift-build").resolve(),
137+
],
138+
)
126139

127140

128141
def main() -> None:
@@ -158,7 +171,8 @@ def main() -> None:
158171
),
159172
)
160173

161-
run_bootstrap(swiftpm_bin_dir=swiftpm_bin_dir)
174+
if is_on_darwin():
175+
run_bootstrap(swiftpm_bin_dir=swiftpm_bin_dir)
162176

163177

164178
if __name__ == "__main__":

0 commit comments

Comments
 (0)