Skip to content

Commit

Permalink
Support building this repo for more platforms, by checking the build …
Browse files Browse the repository at this point in the history
…triple

This is rather than checking the host system, plus removed unnecessary regex checking.
  • Loading branch information
finagolfin committed Apr 12, 2023
1 parent 186fb13 commit 1f97788
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import json
import sys
import os, platform
import re
import subprocess

def printerr(message):
Expand Down Expand Up @@ -159,7 +158,9 @@ def get_swiftpm_options(action, args):
if args.verbose or action == 'install':
swiftpm_args += ['--verbose']

if platform.system() == 'Darwin':
build_target = get_build_target(args)
build_os = build_target.split('-')[2]
if build_os.startswith('macosx'):
swiftpm_args += [
# Relative library rpath for swift; will only be used when /usr/lib/swift
# is not available.
Expand All @@ -168,13 +169,12 @@ def get_swiftpm_options(action, args):
else:
swiftpm_args += [
# Library rpath for swift, dispatch, Foundation, etc. when installing
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os,
]

build_target = get_build_target(args)
cross_compile_hosts = args.cross_compile_hosts
if cross_compile_hosts:
if re.search('-apple-macosx', build_target) and re.match('macosx-', cross_compile_hosts):
if build_os.startswith('macosx') and cross_compile_hosts.startswith('macosx-'):
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
else:
printerr("cannot cross-compile for %s" % cross_compile_hosts)
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_build_target(args):
command = [args.swift_exec, '-print-target-info']
target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip()
args.target_info = json.loads(target_info_json)
if platform.system() == 'Darwin':
if '-apple-macosx' in args.target_info["target"]["unversionedTriple"]:
return args.target_info["target"]["unversionedTriple"]

return args.target_info["target"]["triple"]
Expand Down

0 comments on commit 1f97788

Please sign in to comment.