Skip to content

Commit e6cf5d2

Browse files
Reapply "[libc][windows] start time API implementation (#117775)" (#118886)
1 parent 63dfe70 commit e6cf5d2

34 files changed

+331
-88
lines changed

libc/config/windows/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ set(TARGET_LIBC_ENTRYPOINTS
9595

9696
# errno.h entrypoints
9797
libc.src.errno.errno
98+
99+
# time.h entrypoints
100+
libc.src.time.time
98101
)
99102

100103
set(TARGET_LIBM_ENTRYPOINTS

libc/hdr/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ add_proxy_header_library(
135135
libc.include.llvm-libc-macros.unistd_macros
136136
)
137137

138+
if (WIN32)
139+
set(windows_addtional_time_macros libc.include.llvm-libc-macros.windows.time_macros_ext)
140+
else()
141+
set(windows_addtional_time_macros "")
142+
endif()
143+
138144
add_proxy_header_library(
139145
time_macros
140146
HDRS
141147
time_macros.h
148+
DEPENDS
149+
${windows_addtional_time_macros}
142150
FULL_BUILD_DEPENDS
143151
libc.include.time
144152
libc.include.llvm-libc-macros.time_macros

libc/hdr/time_macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@
1919

2020
#endif // LLVM_LIBC_FULL_BUILD
2121

22+
// TODO: For now, on windows, let's always include the extension header.
23+
// We will need to decide how to export this header.
24+
#ifdef _WIN32
25+
#include "include/llvm-libc-macros/windows/time-macros-ext.h"
26+
#endif // _WIN32
27+
2228
#endif // LLVM_LIBC_HDR_TIME_MACROS_H

libc/hdr/types/clockid_t.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#ifndef LLVM_LIBC_HDR_TYPES_CLOCKID_T_H
1010
#define LLVM_LIBC_HDR_TYPES_CLOCKID_T_H
1111

12-
#ifdef LIBC_FULL_BUILD
12+
// TODO: we will need to decide how to export extension to windows.
13+
#if defined(LIBC_FULL_BUILD) || defined(_WIN32)
1314

1415
#include "include/llvm-libc-types/clockid_t.h"
1516

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_header(
2+
time_macros_ext
3+
HDR
4+
time-macros-ext.h
5+
)
6+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Windows Time Macros Extension -------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H
10+
#define LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H
11+
12+
#define CLOCK_MONOTONIC 0
13+
#define CLOCK_REALTIME 1
14+
#define CLOCK_PROCESS_CPUTIME_ID 2
15+
#define CLOCK_THREAD_CPUTIME_ID 3
16+
17+
#endif // LLVM_LIBC_MACROS_WINDOWS_TIME_MACROS_EXT_H

libc/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_subdirectory(stdio)
1313
add_subdirectory(stdlib)
1414
add_subdirectory(string)
1515
add_subdirectory(wchar)
16+
add_subdirectory(time)
1617

1718
if(${LIBC_TARGET_OS} STREQUAL "linux")
1819
add_subdirectory(dirent)
@@ -40,5 +41,4 @@ add_subdirectory(setjmp)
4041
add_subdirectory(signal)
4142
add_subdirectory(spawn)
4243
add_subdirectory(threads)
43-
add_subdirectory(time)
4444
add_subdirectory(locale)
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
2-
add_subdirectory(${LIBC_TARGET_OS})
3-
endif()
4-
51
add_header_library(
62
units
73
HDRS
@@ -10,3 +6,16 @@ add_header_library(
106
libc.src.__support.common
117
libc.hdr.types.time_t
128
)
9+
10+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
11+
add_subdirectory(${LIBC_TARGET_OS})
12+
else()
13+
return()
14+
endif()
15+
16+
add_object_library(
17+
clock_gettime
18+
ALIAS
19+
DEPENDS
20+
libc.src.__support.time.${LIBC_TARGET_OS}.clock_gettime
21+
)

libc/src/__support/time/linux/clock_gettime.h renamed to libc/src/__support/time/clock_gettime.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
10-
#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
10+
#define LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
1111

1212
#include "hdr/types/clockid_t.h"
1313
#include "hdr/types/struct_timespec.h"
1414
#include "src/__support/error_or.h"
1515

16-
#if defined(SYS_clock_gettime64)
17-
#include <linux/time_types.h>
18-
#endif
19-
2016
namespace LIBC_NAMESPACE_DECL {
2117
namespace internal {
2218
ErrorOr<int> clock_gettime(clockid_t clockid, timespec *ts);
2319
} // namespace internal
2420
} // namespace LIBC_NAMESPACE_DECL
2521

26-
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
22+
#endif // LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
add_object_library(
2+
time_utils
3+
SRCS
4+
time_utils.cpp
5+
HDRS
6+
time_utils.h
7+
DEPENDS
8+
libc.hdr.types.clock_t
9+
libc.hdr.time_macros
10+
)
11+
12+
add_object_library(
13+
clock_gettime
14+
SRCS
15+
clock_gettime.cpp
16+
HDRS
17+
../clock_gettime.h
18+
DEPENDS
19+
libc.hdr.types.clockid_t
20+
libc.hdr.types.struct_timespec
21+
.time_utils
22+
)

0 commit comments

Comments
 (0)