Skip to content

Swift Basic/Driver recognizes OpenBSD. #30083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationOSs[] = {
"iOS",
"Linux",
"FreeBSD",
"OpenBSD",
"Windows",
"Android",
"PS4",
Expand Down Expand Up @@ -258,6 +259,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
case llvm::Triple::FreeBSD:
addPlatformConditionValue(PlatformConditionKind::OS, "FreeBSD");
break;
case llvm::Triple::OpenBSD:
addPlatformConditionValue(PlatformConditionKind::OS, "OpenBSD");
break;
case llvm::Triple::Win32:
if (Target.getEnvironment() == llvm::Triple::Cygnus)
addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin");
Expand Down
3 changes: 2 additions & 1 deletion lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
case llvm::Triple::KFreeBSD:
case llvm::Triple::Lv2:
case llvm::Triple::NetBSD:
case llvm::Triple::OpenBSD:
case llvm::Triple::Solaris:
case llvm::Triple::Minix:
case llvm::Triple::RTEMS:
Expand All @@ -207,6 +206,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
return triple.isAndroid() ? "android" : "linux";
case llvm::Triple::FreeBSD:
return "freebsd";
case llvm::Triple::OpenBSD:
return "openbsd";
case llvm::Triple::Win32:
switch (triple.getEnvironment()) {
case llvm::Triple::Cygnus:
Expand Down
2 changes: 2 additions & 0 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ Driver::buildToolChain(const llvm::opt::InputArgList &ArgList) {
return std::make_unique<toolchains::GenericUnix>(*this, target);
case llvm::Triple::FreeBSD:
return std::make_unique<toolchains::GenericUnix>(*this, target);
case llvm::Triple::OpenBSD:
return std::make_unique<toolchains::OpenBSD>(*this, target);
case llvm::Triple::Win32:
if (target.isWindowsCygwinEnvironment())
return std::make_unique<toolchains::Cygwin>(*this, target);
Expand Down
10 changes: 10 additions & 0 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ class LLVM_LIBRARY_VISIBILITY Cygwin : public GenericUnix {
~Cygwin() = default;
};

class LLVM_LIBRARY_VISIBILITY OpenBSD : public GenericUnix {
protected:
std::string getDefaultLinker() const override;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

public:
OpenBSD(const Driver &D, const llvm::Triple &Triple)
: GenericUnix(D, Triple) {}
~OpenBSD() = default;
};

} // end namespace toolchains
} // end namespace driver
} // end namespace swift
Expand Down
4 changes: 4 additions & 0 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ std::string toolchains::Cygwin::getDefaultLinker() const {
}

std::string toolchains::Cygwin::getTargetForLinker() const { return ""; }

std::string toolchains::OpenBSD::getDefaultLinker() const {
return "lld";
}
19 changes: 19 additions & 0 deletions test/Driver/linker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
// 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
// RUN: %FileCheck -check-prefix WINDOWS-x86_64 %s < %t.windows.txt

// 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
// RUN: %FileCheck -check-prefix OPENBSD-amd64 %s < %t.openbsd.txt

// 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
// RUN: %FileCheck -check-prefix LINUX_DYNLIB-x86_64 %s < %t.linux.dynlib.txt

Expand Down Expand Up @@ -264,6 +267,22 @@
// WINDOWS-x86_64-DAG: -Xlinker -undefined
// WINDOWS-x86_64: -o linker

// OPENBSD-amd64: swift
// OPENBSD-amd64: -o [[OBJECTFILE:.*]]

// OPENBSD-amd64: clang
// OPENBSD-amd64-DAG: -fuse-ld=lld
// OPENBSD-amd64-DAG: [[OBJECTFILE]]
// OPENBSD-amd64-DAG: -lswiftCore
// OPENBSD-amd64-DAG: -L [[STDLIB_PATH:[^ ]+(/|\\\\)lib(/|\\\\)swift(/|\\\\)]]
// OPENBSD-amd64-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
// OPENBSD-amd64-DAG: -F foo -iframework car -F cdr
// OPENBSD-amd64-DAG: -framework bar
// OPENBSD-amd64-DAG: -L baz
// OPENBSD-amd64-DAG: -lboo
// OPENBSD-amd64-DAG: -Xlinker -undefined
// OPENBSD-amd64: -o linker


// COMPLEX: {{(bin/)?}}ld{{"? }}
// COMPLEX-DAG: -dylib
Expand Down
1 change: 1 addition & 0 deletions test/Parse/ConditionalCompilation/basicParseErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct S {
// expected-note@-2{{did you mean 'FreeBSD'?}} {{8-15=FreeBSD}}
// expected-note@-3{{did you mean 'Android'?}} {{8-15=Android}}
// expected-note@-4{{did you mean 'OSX'?}} {{8-15=OSX}}
// expected-note@-5{{did you mean 'OpenBSD'?}} {{8-15=OpenBSD}}
#endif

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