Skip to content

compiler: update aro and translate-c to latest; delete clang translate-c #24497

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Jul 18, 2025

This deletes our implementation of translate-c which is based on libclang and replaces it with one based on arocc and translate-c.

Goodbye, and good riddance, to 5,940 lines of our remaining C++ code in the source repository, with 3,763 remaining.

Progress towards #20630. In the future, Zig will drop the @cImport language builtin, but for now, it remains, backed by Aro instead of Clang.

Progress towards #16270

Upgrade Guide

This is technically a non-breaking change. While breakage is likely due to one C compiler being swapped out for another, if it occurs it is a bug rather than a feature.

So, cross your fingers when you upgrade and report a bug if something breaks.

Merge Checklist

  • get the standalone executable working
  • integrate with frontend using jitCmd
  • capture errors rather than inheriting them to stderr; ignore stdout
  • ship aro C headers and use them for translate-c

@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. and removed breaking Implementing this issue could cause existing code to no longer compile or have different behavior. labels Jul 18, 2025
@andrewrk
Copy link
Member Author

When trying to communicate CLI options to the translate-c executable these are not yet handled:

  • target cpu features
  • -x c
  • warning: unknown argument '--no-default-config'
  • warning: unknown argument '-gdwarf-4'
  • warning: unknown argument '-gdwarf32'
  • warning: unknown argument '-fno-lto'
  • warning: unknown argument '-MD'
  • warning: unknown argument '-MV'
  • warning: unknown argument '-MF'
  • warning: unknown argument '-mred-zone'
  • warning: unknown argument '-fno-omit-frame-pointer'
  • warning: unknown argument '-fno-stack-protector'
  • warning: unknown argument '-fbuiltin'
  • warning: unknown argument '-fno-function-sections'
  • warning: unknown argument '-fno-data-sections'
  • warning: unknown argument '-fasynchronous-unwind-tables'
  • warning: unknown argument '-fno-spell-checking'
  • warning: unknown argument '-fsanitize=undefined'
  • warning: unknown argument '-fno-sanitize=vptr'
  • warning: unknown argument '-fno-sanitize=function'
  • warning: unknown argument '-Xclang -detailed-preprocessing-record'
  • error: invalid target 'x86_64-unknown-linux6.15.1-gnu2.39.0'

manually reduced command:

./translate_c -target x86_64-linux-gnu -fno-PIE -fno-PIC -fhosted -nostdinc -D__GLIBC_MINOR__=39 -isystem /home/andy/dev/zig/lib/include -isystem /nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include -O0 hello.c

fails:

/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
#define __GLIBC_MINOR__ 40
        ^
<command line>:2:9: note: previous definition is here
#define __GLIBC_MINOR__ 39
        ^
/home/andy/dev/zig/lib/include/__stddef_size_t.h:15:33: error: function-like macro '__building_module' is not defined
    (__has_feature(modules) && !__building_module(_Builtin_stddef))
                                ^
/home/andy/dev/zig/lib/include/__stddef_null.h:10:24: error: function-like macro '__building_module' is not defined
#if !defined(NULL) || !__building_module(_Builtin_stddef)
                       ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:43: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                          size_t __nbytes);
                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:50: error: expected ')', found 'an identifier'
                                          size_t __nbytes);
                                                 ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:27:42: note: to match this '('
typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:50: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                          size_t __nbytes);
                                                 ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:28:58: error: expected ';', found ')'
                                          size_t __nbytes);
                                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:44: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                           size_t __nbytes);
                                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:51: error: expected ')', found 'an identifier'
                                           size_t __nbytes);
                                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:36:43: note: to match this '('
typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf,
                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:51: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
                                           size_t __nbytes);
                                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:37:59: error: expected ';', found ')'
                                           size_t __nbytes);
                                                          ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:57:3: error: unknown type name 'cookie_read_function_t'
  cookie_read_function_t *read;         /* Read bytes.  */
  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h:58:3: error: unknown type name 'cookie_write_function_t'
  cookie_write_function_t *write;       /* Write bytes.  */
  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:184:36: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
extern int fclose (FILE *__stream) __nonnull ((1));
                                   ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:561:28: note: expanded from here
# define __nonnull(params) __attribute_nonnull__ (params)
                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:555:57: note: expanded from here
#  define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
                                                        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:273:42: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
                      FILE *__restrict __stream) __wur __nonnull ((3));
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:561:28: note: expanded from here
# define __nonnull(params) __attribute_nonnull__ (params)
                           ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/sys/cdefs.h:555:57: note: expanded from here
#  define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
                                                        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:35: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                  ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:42: error: expected ')', found 'an identifier'
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:23: note: to match this '('
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                      ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:42: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                         ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:49: error: expected identifier or '('
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                                ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:314:68: error: expected ';', found ')'
extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                                                   ^

(truncated)

@andrewrk
Copy link
Member Author

aha, aro does not support clang's C runtime includes, which makes sense.

andy@bark ~/d/z/build-release (aro-translate-c)> ./translate_c -target x86_64-linux-gnu -fno-PIE -fno-PIC -fhosted -nostdinc -D__GLIBC_MINOR__=39 -isystem /home/andy/src/arocc/include -isystem /nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include -O0 hello.c > hello.zig 2>stderr.txt
andy@bark ~/d/z/build-release (aro-translate-c)> stage3/bin/zig run hello.zig -lc
hello world

stderr.txt contains:

/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
#define	__GLIBC_MINOR__	40
        ^
<command line>:2:9: note: previous definition is here
#define __GLIBC_MINOR__ 39
        ^
/nix/store/r25srliigrrv5q3n7y8ms6z10spvjcd9-glibc-2.40-66-dev/include/stdio.h:184:36: warning: unknown attribute '__nonnull__' ignored [-Wunknown-attributes]
extern int fclose (FILE *__stream) __nonnull ((1));
                                   ^

@andrewrk
Copy link
Member Author

@Vexu do you recommend to also ship aro C headers, or do you think it is OK to use clang ones (the files in lib/include)

@Vexu
Copy link
Member

Vexu commented Aug 11, 2025

Using the Clang headers didn't work when I last tried them. I don't remember why, might have been __building_module().

@andrewrk
Copy link
Member Author

I tried using this with tetris, however, translate-c created this dep file:

.zig-cache/tmp/dd9f1705ac09b374/cimport.zig: \
  .zig-cache/tmp/dd9f1705ac09b374/cimport.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/stdio.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/libc-header-start.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/features.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/features-time64.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/wordsize.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/timesize.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/stdc-predef.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/sys/cdefs.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/long-double.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/gnu/stubs.h \
  /home/andy/dev/zig/lib/compiler/aro/include/stddef.h \
  /home/andy/dev/zig/lib/compiler/aro/include/stdarg.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/typesizes.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/time64.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__fpos_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__mbstate_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__fpos64_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__FILE.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/FILE.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/struct_FILE.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/cookie_io_functions_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/stdio_lim.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/floatn.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/floatn-common.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/math.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/math-vector.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/libm-simd-decl-stubs.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/flt-eval-method.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/fp-logb.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/fp-fast.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/mathcalls-helper-functions.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/mathcalls.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/time.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/time.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/clock_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/time_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/struct_tm.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/struct_timespec.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/endian.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/endianness.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/clockid_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/timer_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/struct_itimerspec.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/locale_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__locale_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/stdlib.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/waitflags.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/waitstatus.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/sys/types.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/stdint-intn.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/endian.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/byteswap.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/uintn-identity.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/sys/select.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/select.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/sigset_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/__sigset_t.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/types/struct_timeval.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/pthreadtypes.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/thread-shared-types.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/pthreadtypes-arch.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/atomic_wide_counter.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/struct_mutex.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/struct_rwlock.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/alloca.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/stdlib-float.h \
  /nix/store/57327qk19vkl6p2pgfbqw8vch7167pcl-libepoxy-1.5.10-dev/include/epoxy/gl.h \
  /nix/store/57327qk19vkl6p2pgfbqw8vch7167pcl-libepoxy-1.5.10-dev/include/epoxy/common.h \
  /home/andy/dev/zig/lib/compiler/aro/include/stdbool.h \
  /nix/store/57327qk19vkl6p2pgfbqw8vch7167pcl-libepoxy-1.5.10-dev/include/epoxy/gl_generated.h \
  /home/andy/dev/zig/lib/include/inttypes.h inttypes.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/inttypes.h \
  /home/andy/dev/zig/lib/compiler/aro/include/stdint.h stdint.h \
  /home/andy/dev/zig/lib/include/stdint.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/stdint.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/wchar.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/stdint-uintn.h \
  /nix/store/41pf3md9zgpda9kwh6rzn5kaddf7i0lp-glibc-2.40-66-dev/include/bits/stdint-least.h \
  /nix/store/72n8sv6y88ryi34wakvy3yk1i863k7g5-glfw-3.4/include/GLFW/glfw3.h

which caused ENOENT on inttypes.h

@Vexu
Copy link
Member

Vexu commented Aug 12, 2025

That looks like the bug I fixed in Vexu/arocc@d0ebb59.

@andrewrk
Copy link
Member Author

andrewrk commented Aug 14, 2025

These warnings are a problem:

  • warning: unknown attribute '__nonnull__' translate-c#39
  • error: glibc-2.40-66-dev/include/features.h:422:4: warning: _FORTIFY_SOURCE requires compiling with optimization (-O) [-W#warnings]
  • glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]

Maybe they can be addressed, but also I'm pretty sure they are supposed to be silenced because they are included with -isystem.

Also, what's the best way to convert Aro's errors to an ErrorBundle in Zig? Should we use CObject.Diag.Bundle.parse like we do for Clang?

@ehaas
Copy link
Contributor

ehaas commented Aug 14, 2025

error: glibc-2.40-66-dev/include/features.h:422:4: warning: _FORTIFY_SOURCE requires compiling with optimization (-O) [-W#warnings]

Do you know how _FORTIFY_SOURCE is getting set? And what -O flag is being passed to aro? aro does not add the __OPTIMIZE__ or __OPTIMIZE_SIZE__ defines if -O is set; that would be an easy fix if the issue is that _FORTIFY_SOURCE is correctly set and some optimization flag is being set.

Edit: this one is an explicit #warning so -isystem alone won't fix it https://sourceware.org/git/?p=glibc.git;a=blob;f=include/features.h;h=8515b06b360c768ccf39455c314179b67d070dd4;hb=refs/heads/master#l435

glibc-2.40-66-dev/include/features.h:503:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]

This makes me think aro is finding your system glibc instead of zig's glibc.

@andrewrk
Copy link
Member Author

This makes me think aro is finding your system glibc instead of zig's glibc.

it is indeed, and that is how it is supposed to work when compiling natively on the host.

@ehaas
Copy link
Contributor

ehaas commented Aug 14, 2025

I see. For some reason I was thinking it was maybe getting headers from two different paths, but I see what you're saying about -isystem suppressing warnings. We do have support for classifying source types (user, system, and Included from an "implicit extern C" directory) but we only use it for line markers currently. I can look into using that to suppress warnings as well.

@andrewrk
Copy link
Member Author

Sorry to be clear Aro is not finding system glibc - this is a middle ground between the translate-c package and status quo in which @cImport continues to work but is now powered by Aro. So it's Zig frontend finding the system glibc the same as before, and passing those directories to Aro instead of Clang with -isystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants