Skip to content

Commit 294359b

Browse files
authored
Merge pull request #4804 from kstaring/master
2 parents 51bfa3f + cd52ed6 commit 294359b

File tree

8 files changed

+104
-3
lines changed

8 files changed

+104
-3
lines changed

cmake/modules/FindICU.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ foreach(MODULE ${ICU_FIND_COMPONENTS})
1717

1818
find_path(ICU_${MODULE}_INCLUDE_DIR unicode
1919
HINTS ${PC_ICU_${MODULE}_INCLUDEDIR} ${PC_ICU_${MODULE}_INCLUDE_DIRS})
20-
set(ICU_${MODULE}_INCLUDE_DIR ${ICU_${MODULE}_INCLUDE_DIR})
20+
set(ICU_${MODULE}_INCLUDE_DIRS ${ICU_${MODULE}_INCLUDE_DIR})
2121

2222
find_library(ICU_${MODULE}_LIBRARY NAMES icu${module}
2323
HINTS ${PC_ICU_${MODULE}_LIBDIR} ${PC_ICU_${MODULE}_LIBRARY_DIRS})

stdlib/private/SwiftPrivatePthreadExtras/PthreadBarriers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ public var _stdlib_PTHREAD_BARRIER_SERIAL_THREAD: CInt {
4343
}
4444

4545
public struct _stdlib_pthread_barrier_t {
46+
#if CYGWIN || os(FreeBSD)
47+
var mutex: UnsafeMutablePointer<pthread_mutex_t?>?
48+
var cond: UnsafeMutablePointer<pthread_cond_t?>?
49+
#else
4650
var mutex: UnsafeMutablePointer<pthread_mutex_t>?
4751
var cond: UnsafeMutablePointer<pthread_cond_t>?
52+
#endif
4853

4954
/// The number of threads to synchronize.
5055
var count: CUnsignedInt = 0

stdlib/private/SwiftPrivatePthreadExtras/SwiftPrivatePthreadExtras.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ internal func invokeBlockContext(
5959
return context.run()
6060
}
6161

62+
#if CYGWIN || os(FreeBSD)
63+
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t?>
64+
#else
65+
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t>
66+
#endif
67+
6268
/// Block-based wrapper for `pthread_create`.
6369
public func _stdlib_pthread_create_block<Argument, Result>(
64-
_ attr: UnsafePointer<pthread_attr_t>?,
70+
_ attr: _stdlib_pthread_attr_t?,
6571
_ start_routine: @escaping (Argument) -> Result,
6672
_ arg: Argument
6773
) -> (CInt, pthread_t?) {

stdlib/public/Platform/glibc.modulemap.gyb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ module SwiftGlibc [system] {
2626
link "util"
2727
% end
2828

29+
% if CMAKE_SDK != "FREEBSD":
2930
link "dl"
31+
% end
3032

3133
// C standard library
3234
module C {
@@ -35,6 +37,8 @@ module SwiftGlibc [system] {
3537
header "${GLIBC_INCLUDE_PATH}/complex.h"
3638
export *
3739
}
40+
% end
41+
% if CMAKE_SDK in ["LINUX", "CYGWIN"]:
3842
module pty {
3943
header "${GLIBC_INCLUDE_PATH}/pty.h"
4044
export *
@@ -44,6 +48,16 @@ module SwiftGlibc [system] {
4448
export *
4549
}
4650
% end
51+
% if CMAKE_SDK == "FREEBSD":
52+
module pty {
53+
header "${GLIBC_INCLUDE_PATH}/libutil.h"
54+
export *
55+
}
56+
module utmp {
57+
header "${GLIBC_INCLUDE_PATH}/utmpx.h"
58+
export *
59+
}
60+
% end
4761

4862
% if CMAKE_SDK in ["LINUX", "ANDROID", "CYGWIN"]:
4963
module features {
@@ -355,10 +369,12 @@ module SwiftGlibc [system] {
355369
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/select.h"
356370
export *
357371
}
372+
% if CMAKE_SDK != "FREEBSD":
358373
module sendfile {
359374
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/sendfile.h"
360375
export *
361376
}
377+
% end
362378
module socket {
363379
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/socket.h"
364380
export *
@@ -379,6 +395,12 @@ module SwiftGlibc [system] {
379395
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/types.h"
380396
export *
381397
}
398+
% if CMAKE_SDK in ["FREEBSD"]:
399+
module event {
400+
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/event.h"
401+
export *
402+
}
403+
% end
382404
module uio {
383405
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/uio.h"
384406
export *

stdlib/public/stubs/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ set(LLVM_OPTIONAL_SOURCES
1717
${swift_stubs_objc_sources}
1818
${swift_stubs_unicode_normalization_sources})
1919

20+
# ICU isn't required on Darwin, but is on every other platform.
21+
# Now in case we're cross-compiling from Darwin for another platform,
22+
# the find_package should still be executed.
23+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
24+
set(icu_required "")
25+
else()
26+
set(icu_required "REQUIRED")
27+
endif()
28+
29+
find_package(ICU ${icu_required} COMPONENTS uc)
30+
set(ICU_UC_LIBRARY "")
31+
2032
set(swift_stubs_c_compile_flags ${SWIFT_RUNTIME_CORE_CXX_FLAGS})
2133
list(APPEND swift_stubs_c_compile_flags -DswiftCore_EXPORTS)
2234

stdlib/public/stubs/CommandLine.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extern "C" char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
5757
*outArgLen = *_NSGetArgc();
5858
return *_NSGetArgv();
5959
}
60-
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__)
60+
#elif defined(__linux__) || defined(__CYGWIN__)
6161
SWIFT_RUNTIME_STDLIB_INTERFACE
6262
extern "C" char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
6363
assert(outArgLen != nullptr);
@@ -104,6 +104,57 @@ extern "C" char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
104104
*outArgLen = __argc;
105105
return __argv;
106106
}
107+
#elif defined(__FreeBSD__)
108+
#include <errno.h>
109+
#include <unistd.h>
110+
#include <sys/types.h>
111+
#include <sys/param.h>
112+
#include <sys/sysctl.h>
113+
114+
SWIFT_RUNTIME_STDLIB_INTERFACE
115+
extern "C" char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
116+
assert(outArgLen != nullptr);
117+
118+
if (_swift_stdlib_ProcessOverrideUnsafeArgv) {
119+
*outArgLen = _swift_stdlib_ProcessOverrideUnsafeArgc;
120+
return _swift_stdlib_ProcessOverrideUnsafeArgv;
121+
}
122+
123+
char *argPtr = NULL; // or use ARG_MAX? 8192 is used in LLDB though..
124+
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, getpid() };
125+
size_t argPtrSize = 0;
126+
for (int i = 0; i < 3 && !argPtr; i++) { // give up after 3 tries
127+
if (sysctl(mib, 4, NULL, &argPtrSize, NULL, 0) != -1) {
128+
argPtr = (char *)malloc(argPtrSize);
129+
if (sysctl(mib, 4, argPtr, &argPtrSize, NULL, 0) == -1) {
130+
free(argPtr);
131+
argPtr = NULL;
132+
if (errno != ENOMEM)
133+
break;
134+
}
135+
} else {
136+
break;
137+
}
138+
}
139+
if (!argPtr)
140+
swift::fatalError(0, "fatal error: could not retrieve commandline "
141+
"arguments: sysctl: %s.\n", strerror(errno));
142+
143+
char *curPtr = argPtr;
144+
char *endPtr = argPtr + argPtrSize;
145+
146+
std::vector<char *> argvec;
147+
for (; curPtr < endPtr; curPtr += strlen(curPtr) + 1)
148+
argvec.push_back(strdup(curPtr));
149+
*outArgLen = argvec.size();
150+
char **outBuf = (char **)calloc(argvec.size() + 1, sizeof(char *));
151+
std::copy(argvec.begin(), argvec.end(), outBuf);
152+
outBuf[argvec.size()] = nullptr;
153+
154+
free(argPtr);
155+
156+
return outBuf;
157+
}
107158
#else // __ANDROID__; Add your favorite arch's command line arg grabber here.
108159
SWIFT_RUNTIME_STDLIB_INTERFACE
109160
extern "C" char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {

tools/swift-demangle/swift-demangle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#if defined(__FreeBSD__)
18+
#define _WITH_GETLINE
19+
#endif
20+
1721
#include "swift/Basic/DemangleWrappers.h"
1822
#include "swift/Basic/ManglingMacros.h"
1923
#include "llvm/ADT/SmallString.h"

utils/build-script-impl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ function set_build_options_for_host() {
416416
SWIFT_HOST_VARIANT="freebsd"
417417
SWIFT_HOST_VARIANT_SDK="FREEBSD"
418418
SWIFT_HOST_VARIANT_ARCH="x86_64"
419+
USE_GOLD_LINKER=1
419420
;;
420421
cygwin-x86_64)
421422
SWIFT_HOST_VARIANT="windows"

0 commit comments

Comments
 (0)