Skip to content

Commit 9094f1e

Browse files
michael-yujijakepetroules
authored andcommitted
make FreeBSD triple unversioned
1 parent 0c04134 commit 9094f1e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Sources/SPMBuildCore/Triple+Extensions.swift

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extension Triple {
1616
public var platformBuildPathComponent: String {
1717
if isDarwin() {
1818
return self.tripleString(forPlatformVersion: "")
19+
} else if isFreeBSD() {
20+
return "\(self.archName)-\(self.vendorName)-\(self.osNameUnversioned)"
1921
}
2022

2123
return self.tripleString

Utilities/bootstrap

+28-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ def parse_build_args(args):
266266
args.build_dir,
267267
get_build_target(args,cross_compile=True))
268268
else:
269-
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
269+
if platform.system() == 'FreeBSD':
270+
args.target_dir = os.path.join(args.build_dir, get_unversioned_build_target(args))
271+
else:
272+
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
270273
args.bootstrap_dir = os.path.join(args.target_dir, "bootstrap")
271274
args.conf = 'release' if args.release else 'debug'
272275
args.bin_dir = os.path.join(args.target_dir, args.conf)
@@ -348,6 +351,30 @@ def get_build_target(args, cross_compile=False):
348351
logging.error("get build targets: %s", str(cpe))
349352
raise cpe
350353

354+
def get_unversioned_build_target(args, cross_compile=False):
355+
"""Returns the target-triple of the current machine or for cross-compilation."""
356+
try:
357+
command = [args.swiftc_path, '-print-target-info']
358+
if cross_compile:
359+
cross_compile_json = json.load(open(args.cross_compile_config))
360+
command += ['-target', cross_compile_json["target"]]
361+
logging.debug("Running command >>> %r", command)
362+
target_info_json = subprocess.check_output(command,
363+
stderr=subprocess.PIPE, universal_newlines=True, env=os.environ).strip()
364+
logging.debug("Command returned: %r", target_info_json)
365+
args.target_info = json.loads(target_info_json)
366+
return args.target_info["target"]["unversionedTriple"]
367+
except subprocess.CalledProcessError as cpe:
368+
logging.debug("Command failed...")
369+
# Temporary fallback for Darwin.
370+
if platform.system() == 'Darwin':
371+
macOS_default = 'x86_64-apple-macosx'
372+
logging.debug("we are on Darwin. defaulting to %r", macOS_default)
373+
return macOS_default
374+
else:
375+
logging.error("get build targets: %s", str(cpe))
376+
raise cpe
377+
351378
# -----------------------------------------------------------
352379
# Actions
353380
# -----------------------------------------------------------

0 commit comments

Comments
 (0)