Skip to content

Commit c318dfa

Browse files
authored
improve libc time and MSVC simulator (#5775)
- [libc] 解决由于类unix操作系统发展历史原因fcntl.h定义的标志位在不同编译器中定义不同的问题 - [simulator] 部分宏定义转为全局宏定义以确保vs内置文件可以正确配置 - [simulator] 取消自欺欺人式的警告消除处理方式 - [libc][time] 优化time相关结构体在不同编译器下的包含
1 parent e68f934 commit c318dfa

File tree

8 files changed

+73
-25
lines changed

8 files changed

+73
-25
lines changed

bsp/simulator/drivers/SConscript

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import sys
22
import os
33
from building import *
4+
Import('rtconfig')
45

56
cwd = GetCurrentDir()
67
src = Glob('*.c')
78
LIBS = []
89
LIBPATH = []
910
CPPPATH = [cwd]
11+
CPPDEFINES = []
12+
13+
if rtconfig.CROSS_TOOL == 'msvc':
14+
CPPDEFINES += \
15+
[
16+
# avoid to conflict with the inherent STDC in VS
17+
'_CRT_DECLARE_NONSTDC_NAMES=0',
18+
# errno macro redefinition
19+
'_CRT_ERRNO_DEFINED',
20+
# time.h conflicts
21+
'_CRT_NO_TIME_T',
22+
# disable deprecation of unsafe functions, such as strncpy
23+
'_CRT_SECURE_NO_WARNINGS',
24+
# RT_VESRION conflicts in winuser.h
25+
'NORESOURCE',
26+
]
1027

1128
# remove no need file.
1229
if GetDepend('PKG_USING_GUIENGINE') == False:
@@ -30,7 +47,8 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MODULE') == False:
3047
if sys.platform[0:5]=="linux": #check whether under linux
3148
SrcRemove(src, ['module_win32.c', 'dfs_win32.c'])
3249

33-
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH)
50+
group = DefineGroup('Drivers', src, depend = [''],
51+
CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH, CPPDEFINES=CPPDEFINES)
3452

3553
list = os.listdir(cwd)
3654
for item in list:

bsp/simulator/rtconfig_project.h

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@
1212

1313
#define RT_HEAP_SIZE (1024*1024*8)
1414

15-
#if defined(_MSC_VER)
16-
#define NORESOURCE /* RT_VESRION in winuser.h */
17-
#define _CRT_ERRNO_DEFINED /* errno macro redefinition */
18-
#define _INC_WTIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */
19-
#define _INC_TIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */
20-
#define _CRT_DECLARE_NONSTDC_NAMES 0 /* avoid to conflict with the inherent STDC in VS */
21-
15+
#ifdef _MSC_VER
2216
/* disable some warning in MSC */
23-
#pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */
24-
#pragma warning(disable:4312) /* to ignore: warning C4312: 'type cast' : conversion from 'rt_uint32_t' to 'rt_uint32_t *' */
25-
#pragma warning(disable:4311) /* to ignore: warning C4311: 'type cast' : pointer truncation from 'short *__w64 ' to 'long' */
26-
#pragma warning(disable:4996) /* to ignore: warning C4996: The POSIX name for this item is deprecated. */
27-
#pragma warning(disable:4267) /* to ignore: warning C4267: conversion from 'size_t' to 'rt_size_t', possible loss of data */
28-
#pragma warning(disable:4244) /* to ignore: warning C4244: '=' : conversion from '__w64 int' to 'rt_size_t', possible loss of data */
29-
30-
#endif /* end of _MSC_VER */
17+
// #pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */
18+
#endif /* _MSC_VER */
3119

32-
#endif
20+
#endif /* RTCONFIG_PROJECT_H__ */
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import os
12
from building import *
2-
33
Import('rtconfig')
44

55
src = []
@@ -9,6 +9,13 @@ group = []
99

1010
src += Glob('*.c')
1111

12-
if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
12+
if rtconfig.PLATFORM != 'gcc':
1313
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
list = os.listdir(cwd)
16+
for d in list:
17+
path = os.path.join(cwd, d)
18+
if os.path.isfile(os.path.join(path, 'SConscript')):
19+
group = group + SConscript(os.path.join(d, 'SConscript'))
20+
1421
Return('group')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Because of the history issue, flags in fcntl.h, such as O_CREAT, have difference types of value. Some OS use hex flags and others use octal flags.
2+
3+
In terms of RT-Thread, Keil, IAR and MSVC use octal flags, which is located in the `tcntl/octal` folder; newlib uses hex flags; musl uses octal flags.
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# RT-Thread building script for bridge
2+
3+
import os
4+
from building import *
5+
6+
cwd = GetCurrentDir()
7+
objs = []
8+
list = os.listdir(cwd)
9+
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
14+
15+
Return('objs')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from building import *
2+
Import('rtconfig')
3+
4+
src = []
5+
cwd = GetCurrentDir()
6+
CPPPATH = [cwd]
7+
group = []
8+
9+
if rtconfig.PLATFORM == 'armcc' or\
10+
rtconfig.PLATFORM == 'armclang' or\
11+
rtconfig.PLATFORM == 'iar' or\
12+
rtconfig.CROSS_TOOL == 'msvc':
13+
group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH)
14+
Return('group')

components/libc/compilers/common/sys/time.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include <time.h>
1919
#ifdef _WIN32
2020
#include <winsock.h> /* for struct timeval */
21-
#endif
21+
#include <corecrt.h> /* for __time64_t */
22+
typedef __time64_t time_t;
23+
#endif /* _WIN32 */
2224

2325
#ifdef __cplusplus
2426
extern "C" {
@@ -50,17 +52,17 @@ struct timeval
5052
time_t tv_sec; /* seconds */
5153
suseconds_t tv_usec; /* and microseconds */
5254
};
53-
#endif
55+
#endif /* !defined(_TIMEVAL_DEFINED) && !defined(_WIN32) */
5456

55-
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
56-
!(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
57-
!defined(_WIN32)
57+
#if defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ >= 8010001))
5858
struct timespec
5959
{
6060
time_t tv_sec; /* seconds */
6161
long tv_nsec; /* and nanoseconds */
6262
};
63+
#endif /* defined(__ARMCC_VERSION) || defined(_WIN32) || (defined(__ICCARM__) && (__VER__ >= 8010001)) */
6364

65+
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/)
6466
/*
6567
* Structure defined by POSIX.1b to be like a itimerval, but with
6668
* timespecs. Used in the timer_*() system calls.
@@ -70,7 +72,7 @@ struct itimerspec
7072
struct timespec it_interval;
7173
struct timespec it_value;
7274
};
73-
#endif
75+
#endif /* !(defined(__GNUC__) && !defined(__ARMCC_VERSION)) */
7476

7577
int stime(const time_t *t);
7678
time_t timegm(struct tm * const t);

0 commit comments

Comments
 (0)