Skip to content

Commit

Permalink
Merge pull request #992 from managarm/cshim
Browse files Browse the repository at this point in the history
misc: Depend on 'cshim', if available, instead of host freestanding headers
  • Loading branch information
mintsuki authored Feb 17, 2024
2 parents b5abcf6 + 42b3c58 commit 21d0b1b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 26 deletions.
56 changes: 32 additions & 24 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ internal_conf = configuration_data()
mlibc_conf = configuration_data()

if not headers_only
cshim_dep = dependency('cshim',
required: false,
fallback: ['cshim', 'cshim_dep'])
libc_deps += cshim_dep
rtdl_deps += cshim_dep

cxxshim_dep = dependency('cxxshim',
required: false,
fallback: ['cxxshim', 'cxxshim_dep'])
Expand All @@ -62,40 +68,42 @@ if not headers_only
cpp_compiler = meson.get_compiler('cpp')

add_project_arguments('-Wno-unused-function', '-D__MLIBC_BUILDING_MLIBC', language: ['c', 'cpp'])
add_project_arguments('-nostdinc', '-fno-builtin', language: ['c', 'cpp'])
add_project_arguments('-nostdinc', '-fno-builtin', '-ffreestanding', language: ['c', 'cpp'])
add_project_arguments('-Werror=misleading-indentation', language: ['c', 'cpp'])
add_project_arguments('-fno-rtti', '-fno-exceptions', language: 'cpp')
add_project_link_arguments('-nostdlib', language: ['c', 'cpp'])

searchdirs = run_command(c_compiler.cmd_array(), '-print-search-dirs',
check: true).stdout()
searchdirs_arr = searchdirs.split('\n')
searchline = 'install: '
ccdir = ''
if c_compiler.get_id() == 'clang'
searchline = 'libraries: ='
endif
if not cshim_dep.found()
searchdirs = run_command(c_compiler.cmd_array(), '-print-search-dirs',
check: true).stdout()
searchdirs_arr = searchdirs.split('\n')
searchline = 'install: '
ccdir = ''
if c_compiler.get_id() == 'clang'
searchline = 'libraries: ='
endif

foreach line : searchdirs_arr
if line.startswith(searchline)
ccdir = line.strip(searchline)
ccdir = ccdir.split(':')[0]
break
foreach line : searchdirs_arr
if line.startswith(searchline)
ccdir = line.strip(searchline)
ccdir = ccdir.split(':')[0]
break
endif
endforeach

if ccdir == ''
error('could not find compiler-specific header directory')
endif
endforeach

if ccdir == ''
error('could not find compiler-specific header directory')
endif
if c_compiler.get_id() == 'gcc' and fs.exists(ccdir / 'include-fixed')
rtdl_include_dirs += include_directories(ccdir / 'include-fixed')
libc_include_dirs += include_directories(ccdir / 'include-fixed')
endif

if c_compiler.get_id() == 'gcc' and fs.exists(ccdir / 'include-fixed')
rtdl_include_dirs += include_directories(ccdir / 'include-fixed')
libc_include_dirs += include_directories(ccdir / 'include-fixed')
rtdl_include_dirs += include_directories(ccdir / 'include')
libc_include_dirs += include_directories(ccdir / 'include')
endif

rtdl_include_dirs += include_directories(ccdir / 'include')
libc_include_dirs += include_directories(ccdir / 'include')

if not cxxshim_dep.found()
cplusplus_include_path = []

Expand Down
47 changes: 47 additions & 0 deletions options/ansi/include/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#define CHAR_BIT 8

#ifndef MB_LEN_MAX
# define MB_LEN_MAX 4
#endif

#ifdef LONG_MAX
# ifdef LONG_MAX == INT32_MAX
# define LONG_BIT 32
Expand All @@ -21,17 +25,60 @@
# error "Unsupported configuration, please define either LONG_MAX or __LONG_MAX__"
#endif

#undef SCHAR_MIN
#undef SCHAR_MAX
#undef CHAR_MIN
#undef CHAR_MAX
#undef UCHAR_MAX
#undef SHRT_MIN
#undef SHRT_MAX
#undef USHRT_MAX
#undef INT_MIN
#undef INT_MAX
#undef UINT_MAX
#undef LONG_MIN
#undef LONG_MAX
#undef ULONG_MAX
#undef LLONG_MIN
#undef LLONG_MAX
#undef ULLONG_MAX

#define SCHAR_MIN (-__SCHAR_MAX__ - 1)
#define SCHAR_MAX __SCHAR_MAX__
#if __SCHAR_MAX__ == __INT_MAX__
# define UCHAR_MAX (__SCHAR_MAX__ * 2U + 1U)
#else
# define UCHAR_MAX (__SCHAR_MAX__ * 2 + 1)
#endif

#ifdef __CHAR_UNSIGNED__
# define CHAR_MAX UCHAR_MAX
# if __SCHAR_MAX__ == __INT_MAX__
# define CHAR_MIN 0U
# else
# define CHAR_MIN 0
# endif
#else
# define CHAR_MAX SCHAR_MAX
# define CHAR_MIN SCHAR_MIN
#endif

#define SHRT_MIN (-__SHRT_MAX__ - 1)
#define SHRT_MAX __SHRT_MAX__
#if __SHRT_MAX_ == __INT_MAX__
# define USHRT_MAX (__SHRT_MAX__ * 2U + 1U)
#else
# define USHRT_MAX (__SHRT_MAX__ * 2 + 1)
#endif

#define INT_MIN (-__INT_MAX__ - 1)
#define INT_MAX __INT_MAX__
#define UINT_MAX (__INT_MAX__ * 2 + 1)

#define LONG_MIN (-__LONG_MAX__ - 1L)
#define LONG_MAX __LONG_MAX__
#define ULONG_MAX (__LONG_MAX__ * 2UL + 1UL)

#define LLONG_MIN (-__LONG_LONG_MAX__ - 1LL)
#define LLONG_MAX __LONG_LONG_MAX__
#define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1ULL)
Expand Down
1 change: 1 addition & 0 deletions options/ansi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,6 @@ if not headers_only
'musl-generic-math/truncl.c',
pic: true,
include_directories: libc_include_dirs,
dependencies: libc_deps,
c_args: ['-Wno-unused', '-Wno-implicit', '-Wno-parentheses', '-Wno-sign-compare', '-Wno-attributes', '-Wno-unknown-pragmas', '-Wno-maybe-uninitialized'])
endif
1 change: 1 addition & 0 deletions options/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if not headers_only
'musl-generic-regex/tre-mem.c',
pic: true,
include_directories: libc_include_dirs,
dependencies: libc_deps,
c_args: ['-Wno-unused', '-Wno-implicit', '-Wno-parentheses', '-Wno-sign-compare', '-Wno-attributes', '-Wno-unknown-pragmas', '-Wno-implicit-fallthrough']
)
endif
Expand Down
4 changes: 4 additions & 0 deletions subprojects/cshim.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
directory = cshim
url = https://github.com/managarm/cshim.git
revision = trunk
2 changes: 1 addition & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ foreach test_name : all_test_cases
should_fail = fail_test_cases.contains(test_name)
exec = executable(test_exec_name, [test_name + '.c', test_sources],
link_with: libc, include_directories: libc_include_dirs,
dependencies: rtlib_deps,
dependencies: rtdl_deps + rtlib_deps,
build_rpath: meson.build_root(),
override_options: test_override_options,
c_args: test_c_args,
Expand Down
2 changes: 1 addition & 1 deletion tests/rtdl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ foreach test_name : rtdl_test_cases

exec = executable('rtdl-' + test_name, [test_name / 'test.c', test_sources],
link_with: test_link_with + libc, include_directories: libc_include_dirs,
dependencies: rtlib_deps,
dependencies: rtdl_deps + rtlib_deps,
build_rpath: test_rpath,
override_options: test_override_options,
c_args: test_c_args,
Expand Down

0 comments on commit 21d0b1b

Please sign in to comment.