authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-17 11:09:53-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-17 11:09:53-04:00
log5039a5db8365413794b0522a51137d3e97d8ba5d
tree3f867b79304fa70b8486253054aa4edacf8fa0fc
parentcfa247e53b15377330f34817333f24cc494b8f60
parent69d6f2e1b821a5cc089534c59cb2e881c6d184b1
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17558 from xxxbxxx/glibc-strtoul

build compatibility for c++ & linux

3 files changed, 22 insertions(+), 2 deletions(-)

build.zig+13-2
...@@ -735,7 +735,11 @@ fn addCxxKnownPath(...@@ -735,7 +735,11 @@ fn addCxxKnownPath(
735) !void {735) !void {
736 if (!std.process.can_spawn)736 if (!std.process.can_spawn)
737 return error.RequiredLibraryNotFound;737 return error.RequiredLibraryNotFound;
738 const path_padded = b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });738
739 const path_padded = if (ctx.cxx_compiler_arg1.len > 0)
740 b.exec(&.{ ctx.cxx_compiler, ctx.cxx_compiler_arg1, b.fmt("-print-file-name={s}", .{objname}) })
741 else
742 b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });
739 var tokenizer = mem.tokenizeAny(u8, path_padded, "\r\n");743 var tokenizer = mem.tokenizeAny(u8, path_padded, "\r\n");
740 const path_unpadded = tokenizer.next().?;744 const path_unpadded = tokenizer.next().?;
741 if (mem.eql(u8, path_unpadded, objname)) {745 if (mem.eql(u8, path_unpadded, objname)) {
...@@ -778,6 +782,7 @@ const CMakeConfig = struct {...@@ -778,6 +782,7 @@ const CMakeConfig = struct {
778 cmake_static_library_prefix: []const u8,782 cmake_static_library_prefix: []const u8,
779 cmake_static_library_suffix: []const u8,783 cmake_static_library_suffix: []const u8,
780 cxx_compiler: []const u8,784 cxx_compiler: []const u8,
785 cxx_compiler_arg1: []const u8,
781 lld_include_dir: []const u8,786 lld_include_dir: []const u8,
782 lld_libraries: []const u8,787 lld_libraries: []const u8,
783 clang_libraries: []const u8,788 clang_libraries: []const u8,
...@@ -844,6 +849,7 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {...@@ -844,6 +849,7 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
844 .cmake_static_library_prefix = undefined,849 .cmake_static_library_prefix = undefined,
845 .cmake_static_library_suffix = undefined,850 .cmake_static_library_suffix = undefined,
846 .cxx_compiler = undefined,851 .cxx_compiler = undefined,
852 .cxx_compiler_arg1 = "",
847 .lld_include_dir = undefined,853 .lld_include_dir = undefined,
848 .lld_libraries = undefined,854 .lld_libraries = undefined,
849 .clang_libraries = undefined,855 .clang_libraries = undefined,
...@@ -875,6 +881,10 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {...@@ -875,6 +881,10 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
875 .prefix = "#define ZIG_CXX_COMPILER ",881 .prefix = "#define ZIG_CXX_COMPILER ",
876 .field = "cxx_compiler",882 .field = "cxx_compiler",
877 },883 },
884 .{
885 .prefix = "#define ZIG_CXX_COMPILER_ARG1 ",
886 .field = "cxx_compiler_arg1",
887 },
878 .{888 .{
879 .prefix = "#define ZIG_LLD_INCLUDE_PATH ",889 .prefix = "#define ZIG_LLD_INCLUDE_PATH ",
880 .field = "lld_include_dir",890 .field = "lld_include_dir",
...@@ -917,7 +927,8 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {...@@ -917,7 +927,8 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
917 var it = mem.splitScalar(u8, line, '"');927 var it = mem.splitScalar(u8, line, '"');
918 _ = it.first(); // skip the stuff before the quote928 _ = it.first(); // skip the stuff before the quote
919 const quoted = it.next().?; // the stuff inside the quote929 const quoted = it.next().?; // the stuff inside the quote
920 @field(ctx, mapping.field) = toNativePathSep(b, quoted);930 const trimmed = mem.trim(u8, quoted, " ");
931 @field(ctx, mapping.field) = toNativePathSep(b, trimmed);
921 }932 }
922 }933 }
923 if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {934 if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {
lib/libc/include/generic-glibc/features.h+8
...@@ -469,6 +469,11 @@...@@ -469,6 +469,11 @@
469# define __GLIBC_USE_DEPRECATED_SCANF 0469# define __GLIBC_USE_DEPRECATED_SCANF 0
470#endif470#endif
471471
472
473/* support for ISO C2X strtol was added in 2.38
474 * glibc commit 64924422a99690d147a166b4de3103f3bf3eaf6c
475 */
476#if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) || __GLIBC__ > 2
472/* ISO C2X added support for a 0b or 0B prefix on binary constants as477/* ISO C2X added support for a 0b or 0B prefix on binary constants as
473 inputs to strtol-family functions (base 0 or 2). This macro is478 inputs to strtol-family functions (base 0 or 2). This macro is
474 used to condition redirection in headers to allow that redirection479 used to condition redirection in headers to allow that redirection
...@@ -479,6 +484,9 @@...@@ -479,6 +484,9 @@
479#else484#else
480# define __GLIBC_USE_C2X_STRTOL 0485# define __GLIBC_USE_C2X_STRTOL 0
481#endif486#endif
487#else /* glibc 2.37 or lower */
488# define __GLIBC_USE_C2X_STRTOL 0
489#endif
482490
483/* Get definitions of __STDC_* predefined macros, if the compiler has491/* Get definitions of __STDC_* predefined macros, if the compiler has
484 not preincluded this header automatically. */492 not preincluded this header automatically. */
stage1/config.h.in+1
...@@ -21,6 +21,7 @@...@@ -21,6 +21,7 @@
21#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"21#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"
22#define ZIG_CMAKE_STATIC_LIBRARY_SUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@"22#define ZIG_CMAKE_STATIC_LIBRARY_SUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@"
23#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"23#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
24#define ZIG_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@"
24#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"25#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
25#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"26#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
26#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"27#define ZIG_LLD_LIBRARIES "@LLD_LIBRARIES@"