Skip to content

Commit 0d3b92d

Browse files
committed
Swift Basic/Driver recognizes OpenBSD.
Add the platform conditional and set up other basics for the toolchain. The ConditionalCompilation tests are updated to match, since otherwise they seem to trip when building on non-OpenBSD platforms. The Driver/linker test is updated to ensure lld is passed on this platform. Note that OpenBSD calls "x86_64" as "amd64", so we use that name for the architecture instead of trying to alias one to the other, as this makes things simpler.
1 parent dddcfb8 commit 0d3b92d

File tree

7 files changed

+42
-1
lines changed

7 files changed

+42
-1
lines changed

lib/Basic/LangOptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationOSs[] = {
4545
"iOS",
4646
"Linux",
4747
"FreeBSD",
48+
"OpenBSD",
4849
"Windows",
4950
"Android",
5051
"PS4",
@@ -258,6 +259,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
258259
case llvm::Triple::FreeBSD:
259260
addPlatformConditionValue(PlatformConditionKind::OS, "FreeBSD");
260261
break;
262+
case llvm::Triple::OpenBSD:
263+
addPlatformConditionValue(PlatformConditionKind::OS, "OpenBSD");
264+
break;
261265
case llvm::Triple::Win32:
262266
if (Target.getEnvironment() == llvm::Triple::Cygnus)
263267
addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin");

lib/Basic/Platform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
180180
case llvm::Triple::KFreeBSD:
181181
case llvm::Triple::Lv2:
182182
case llvm::Triple::NetBSD:
183-
case llvm::Triple::OpenBSD:
184183
case llvm::Triple::Solaris:
185184
case llvm::Triple::Minix:
186185
case llvm::Triple::RTEMS:
@@ -207,6 +206,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
207206
return triple.isAndroid() ? "android" : "linux";
208207
case llvm::Triple::FreeBSD:
209208
return "freebsd";
209+
case llvm::Triple::OpenBSD:
210+
return "openbsd";
210211
case llvm::Triple::Win32:
211212
switch (triple.getEnvironment()) {
212213
case llvm::Triple::Cygnus:

lib/Driver/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
267267
return std::make_unique<toolchains::GenericUnix>(*this, target);
268268
case llvm::Triple::FreeBSD:
269269
return std::make_unique<toolchains::GenericUnix>(*this, target);
270+
case llvm::Triple::OpenBSD:
271+
return std::make_unique<toolchains::OpenBSD>(*this, target);
270272
case llvm::Triple::Win32:
271273
if (target.isWindowsCygwinEnvironment())
272274
return std::make_unique<toolchains::Cygwin>(*this, target);

lib/Driver/ToolChains.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ class LLVM_LIBRARY_VISIBILITY Cygwin : public GenericUnix {
157157
~Cygwin() = default;
158158
};
159159

160+
class LLVM_LIBRARY_VISIBILITY OpenBSD : public GenericUnix {
161+
protected:
162+
std::string getDefaultLinker() const override;
163+
164+
public:
165+
OpenBSD(const Driver &D, const llvm::Triple &Triple)
166+
: GenericUnix(D, Triple) {}
167+
~OpenBSD() = default;
168+
};
169+
160170
} // end namespace toolchains
161171
} // end namespace driver
162172
} // end namespace swift

lib/Driver/UnixToolChains.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,7 @@ std::string toolchains::Cygwin::getDefaultLinker() const {
389389
}
390390

391391
std::string toolchains::Cygwin::getTargetForLinker() const { return ""; }
392+
393+
std::string toolchains::OpenBSD::getDefaultLinker() const {
394+
return "lld";
395+
}

test/Driver/linker.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-unknown-windows-msvc -Ffoo -Fsystem car -F cdr -framework bar -Lbaz -lboo -Xlinker -undefined %s 2>&1 > %t.windows.txt
3838
// RUN: %FileCheck -check-prefix WINDOWS-x86_64 %s < %t.windows.txt
3939

40+
// RUN: %swiftc_driver -driver-print-jobs -target amd64-unknown-openbsd -Ffoo -Fsystem car -F cdr -framework bar -Lbaz -lboo -Xlinker -undefined %s 2>&1 > %t.openbsd.txt
41+
// RUN: %FileCheck -check-prefix OPENBSD-amd64 %s < %t.openbsd.txt
42+
4043
// RUN: %swiftc_driver -driver-print-jobs -emit-library -target x86_64-unknown-linux-gnu %s -Lbar -o dynlib.out 2>&1 > %t.linux.dynlib.txt
4144
// RUN: %FileCheck -check-prefix LINUX_DYNLIB-x86_64 %s < %t.linux.dynlib.txt
4245

@@ -264,6 +267,22 @@
264267
// WINDOWS-x86_64-DAG: -Xlinker -undefined
265268
// WINDOWS-x86_64: -o linker
266269

270+
// OPENBSD-amd64: swift
271+
// OPENBSD-amd64: -o [[OBJECTFILE:.*]]
272+
273+
// OPENBSD-amd64: clang
274+
// OPENBSD-amd64-DAG: -fuse-ld=lld
275+
// OPENBSD-amd64-DAG: [[OBJECTFILE]]
276+
// OPENBSD-amd64-DAG: -lswiftCore
277+
// OPENBSD-amd64-DAG: -L [[STDLIB_PATH:[^ ]+(/|\\\\)lib(/|\\\\)swift(/|\\\\)]]
278+
// OPENBSD-amd64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
279+
// OPENBSD-amd64-DAG: -F foo -iframework car -F cdr
280+
// OPENBSD-amd64-DAG: -framework bar
281+
// OPENBSD-amd64-DAG: -L baz
282+
// OPENBSD-amd64-DAG: -lboo
283+
// OPENBSD-amd64-DAG: -Xlinker -undefined
284+
// OPENBSD-amd64: -o linker
285+
267286

268287
// COMPLEX: {{(bin/)?}}ld{{"? }}
269288
// COMPLEX-DAG: -dylib

test/Parse/ConditionalCompilation/basicParseErrors.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct S {
7878
// expected-note@-2{{did you mean 'FreeBSD'?}} {{8-15=FreeBSD}}
7979
// expected-note@-3{{did you mean 'Android'?}} {{8-15=Android}}
8080
// expected-note@-4{{did you mean 'OSX'?}} {{8-15=OSX}}
81+
// expected-note@-5{{did you mean 'OpenBSD'?}} {{8-15=OpenBSD}}
8182
#endif
8283

8384
#if arch(leg) // expected-warning {{unknown architecture for build configuration 'arch'}} expected-note{{did you mean 'arm'?}} {{10-13=arm}}

0 commit comments

Comments
 (0)