Skip to content

Commit 16de5d1

Browse files
committed
Merge pull request #203 from landonf/landonf/freebsd-patchset-1
Partial FreeBSD Support
2 parents 884df46 + c4daece commit 16de5d1

File tree

16 files changed

+69
-17
lines changed

16 files changed

+69
-17
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
397397

398398
set(SWIFT_PRIMARY_VARIANT_SDK_default "LINUX")
399399
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
400+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
401+
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64" "x86_64-freebsd10")
402+
403+
set(CMAKE_EXECUTABLE_FORMAT "ELF")
404+
405+
set(SWIFT_HOST_VARIANT "freebsd" CACHE STRING
406+
"Deployment OS for Swift host tools (the compiler) [freebsd].")
407+
408+
set(SWIFT_HOST_VARIANT_SDK "FREEBSD")
409+
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
410+
411+
set(SWIFT_PRIMARY_VARIANT_SDK_default "FREEBSD")
412+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
400413
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
401414
# Set defaults.
402415

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ function(_add_variant_link_flags
151151

152152
if("${sdk}" STREQUAL "LINUX")
153153
list(APPEND result "-lpthread" "-ldl")
154+
elseif("${sdk}" STREQUAL "FREEBSD")
155+
# No extra libraries required.
154156
else()
155157
list(APPEND result "-lobjc")
156158
endif()

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ namespace swift {
173173
Target.getiOSVersion(major, minor, revision);
174174
} else if (Target.isWatchOS()) {
175175
Target.getOSVersion(major, minor, revision);
176-
} else if (Target.isOSLinux() || Target.getTriple().empty()) {
176+
} else if (Target.isOSLinux() || Target.isOSFreeBSD() ||
177+
Target.getTriple().empty())
178+
{
177179
major = minor = revision = 0;
178180
} else {
179181
llvm_unreachable("Unsupported target OS");

lib/Basic/LangOptions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const std::vector<std::string> LangOptions::SupportedOSBuildConfigArguments = {
2828
"tvOS",
2929
"watchOS",
3030
"iOS",
31-
"Linux"
31+
"Linux",
32+
"FreeBSD"
3233
};
3334

3435
const std::vector<std::string> LangOptions::SupportedArchBuildConfigArguments = {
@@ -98,6 +99,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
9899
addTargetConfigOption("os", "iOS");
99100
else if (triple.isOSLinux())
100101
addTargetConfigOption("os", "Linux");
102+
else if (triple.isOSFreeBSD())
103+
addTargetConfigOption("os", "FreeBSD");
101104
else {
102105
UnsupportedOS = true;
103106
}

lib/Basic/Platform.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
6464
if (triple.isOSLinux())
6565
return "linux";
6666

67+
if (triple.isOSFreeBSD())
68+
return "freebsd";
69+
6770
return "";
6871
}

lib/Driver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ set(swiftDriver_sources
1212
Types.cpp
1313
)
1414

15+
set(swiftDriver_targetDefines)
16+
1517
add_swift_library(swiftDriver
1618
${swiftDriver_sources}
1719
DEPENDS SwiftOptions

lib/Driver/Driver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,10 @@ const ToolChain *Driver::getToolChain(const ArgList &Args) const {
20362036
TC = new toolchains::Darwin(*this, Target);
20372037
break;
20382038
case llvm::Triple::Linux:
2039-
TC = new toolchains::Linux(*this, Target);
2039+
TC = new toolchains::GenericUnix(*this, Target);
2040+
break;
2041+
case llvm::Triple::FreeBSD:
2042+
TC = new toolchains::GenericUnix(*this, Target);
20402043
break;
20412044
default:
20422045
TC = nullptr;

lib/Driver/ToolChains.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,8 +999,8 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
999999
}
10001000

10011001
ToolChain::InvocationInfo
1002-
toolchains::Linux::constructInvocation(const InterpretJobAction &job,
1003-
const JobContext &context) const {
1002+
toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
1003+
const JobContext &context) const {
10041004
InvocationInfo II = ToolChain::constructInvocation(job, context);
10051005

10061006
SmallString<128> runtimeLibraryPath;
@@ -1014,8 +1014,8 @@ toolchains::Linux::constructInvocation(const InterpretJobAction &job,
10141014

10151015

10161016
ToolChain::InvocationInfo
1017-
toolchains::Linux::constructInvocation(const AutolinkExtractJobAction &job,
1018-
const JobContext &context) const {
1017+
toolchains::GenericUnix::constructInvocation(const AutolinkExtractJobAction &job,
1018+
const JobContext &context) const {
10191019
assert(context.Output.getPrimaryOutputType() == types::TY_AutolinkFile);
10201020

10211021
ArgStringList Arguments;
@@ -1030,8 +1030,8 @@ toolchains::Linux::constructInvocation(const AutolinkExtractJobAction &job,
10301030
}
10311031

10321032
ToolChain::InvocationInfo
1033-
toolchains::Linux::constructInvocation(const LinkJobAction &job,
1034-
const JobContext &context) const {
1033+
toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
1034+
const JobContext &context) const {
10351035
const Driver &D = getDriver();
10361036

10371037
assert(context.Output.getPrimaryOutputType() == types::TY_Image &&

lib/Driver/ToolChains.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
3636

3737
};
3838

39-
class LLVM_LIBRARY_VISIBILITY Linux : public ToolChain {
39+
class LLVM_LIBRARY_VISIBILITY GenericUnix : public ToolChain {
4040
protected:
4141
InvocationInfo constructInvocation(const InterpretJobAction &job,
4242
const JobContext &context) const override;
@@ -46,12 +46,13 @@ class LLVM_LIBRARY_VISIBILITY Linux : public ToolChain {
4646
const JobContext &context) const override;
4747

4848
public:
49-
Linux(const Driver &D, const llvm::Triple &Triple) : ToolChain(D, Triple) {}
50-
~Linux() = default;
49+
GenericUnix(const Driver &D, const llvm::Triple &Triple) : ToolChain(D, Triple) {}
50+
~GenericUnix() = default;
5151
};
5252

5353
} // end namespace toolchains
5454
} // end namespace driver
5555
} // end namespace swift
5656

5757
#endif
58+

stdlib/public/core/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ else()
154154
# -Wl,--whole-archive swiftRuntime -Wl,--no-whole-archive)
155155
list(APPEND swift_core_private_link_libraries swiftRuntime swiftStdlibStubs)
156156
find_package(ICU REQUIRED COMPONENTS uc i18n)
157+
list(APPEND swift_core_private_link_libraries
158+
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY})
159+
endif()
160+
161+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
157162
find_package(BSD REQUIRED)
158163
list(APPEND swift_core_private_link_libraries
159-
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
160164
${BSD_LIBRARIES})
161165
endif()
162166

0 commit comments

Comments
 (0)