Skip to content

Use bundled UUID #1819

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 3 commits into from
Jan 17, 2019
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
34 changes: 29 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "")
find_package(CURL REQUIRED)
find_package(ICU COMPONENTS uc i18n REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(UUID REQUIRED)

include(SwiftSupport)
include(GNUInstallDirs)
Expand Down Expand Up @@ -57,6 +56,27 @@ ExternalProject_Add(CoreFoundation
${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install)
ExternalProject_Get_Property(CoreFoundation install_dir)

add_library(uuid
STATIC
uuid/uuid.h
uuid/uuid.c)
set_target_properties(uuid
PROPERTIES
POSITION_INDEPENDENT_CODE YES)
# Add an include directory for the CoreFoundation framework headers to satisfy
# the dependency on TargetConditionals.h
target_compile_options(uuid
PUBLIC
-I${install_dir}/System/Library/Frameworks/CoreFoundation.framework/Headers)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
target_compile_definitions(uuid
PRIVATE
_CRT_NONSTDC_NO_WARNINGS
_CRT_SECURE_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS)
endif()
add_dependencies(uuid CoreFoundation)

set(swift_optimization_flags)
if(CMAKE_BUILD_TYPE MATCHES Release)
set(swift_optimization_flags -O)
Expand Down Expand Up @@ -262,7 +282,8 @@ add_swift_library(Foundation
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
${LIBXML2_LIBRARIES}
${libdispatch_ldflags}
${uuid_LIBRARIES}
-L${CMAKE_CURRENT_BINARY_DIR}
-luuid
-Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN"
SWIFT_FLAGS
-DDEPLOYMENT_RUNTIME_SWIFT
Expand All @@ -278,11 +299,12 @@ if(NOT BUILD_SHARED_LIBS)
set(Foundation_INTERFACE_LIBRARIES
-L${install_dir}/usr/lib
-lCoreFoundation
-L${CMAKE_CURRENT_BINARY_DIR}
-luuid
${CURL_LIBRARIES}
${ICU_UC_LIBRARY}
${ICU_I18N_LIBRARY}
${LIBXML2_LIBRARIES}
${uuid_LIBRARIES})
${LIBXML2_LIBRARIES})
endif()

add_swift_executable(plutil
Expand All @@ -293,8 +315,8 @@ add_swift_executable(plutil
${deployment_enable_libdispatch}
-F${install_dir}/System/Library/Frameworks
LINK_FLAGS
-L${CMAKE_CURRENT_BINARY_DIR}
${libdispatch_ldflags}
-L${CMAKE_CURRENT_BINARY_DIR}
-lFoundation
${Foundation_INTERFACE_LIBRARIES}
-Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}"
Expand All @@ -307,6 +329,7 @@ add_swift_executable(plutil
${swift_enable_testing}
${swift_optimization_flags}
DEPENDS
uuid
Foundation
CoreFoundation)

Expand All @@ -328,6 +351,7 @@ if(ENABLE_TESTING)
-I;${ICU_INCLUDE_DIR}
${libdispatch_cflags}
DEPENDS
uuid
Foundation
CoreFoundation)

Expand Down
24 changes: 22 additions & 2 deletions uuid/uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#elif defined(_WIN32)
#include <io.h>
#endif
#include <stdio.h>

#if TARGET_OS_MAC
Expand All @@ -61,9 +65,25 @@ static inline void nanotime(struct timespec *tv) {
clock_gettime(CLOCK_MONOTONIC, tv);
}

#elif TARGET_OS_WINDOWS
#include <time.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

static inline void nanotime(struct timespec *tv) {
FILETIME ftTime;

GetSystemTimePreciseAsFileTime(&ftTime);

uint64_t Value = (((uint64_t)ftTime.dwHighDateTime << 32) | ftTime.dwLowDateTime);

tv->tv_sec = Value / 1000000000;
tv->tv_nsec = Value - (tv->tv_sec * 1000000000);
}
#endif

static inline void read_random(void *buffer, u_int numBytes) {
static inline void read_random(void *buffer, unsigned numBytes) {
int fd = open("/dev/urandom", O_RDONLY);
read(fd, buffer, numBytes);
close(fd);
Expand Down Expand Up @@ -227,4 +247,4 @@ void
uuid_unparse(const uuid_t uu, uuid_string_t out)
{
uuid_unparse_upper(uu, out);
}
}