Skip to content
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

Getting compiler errors about a missing __COLD attribute? from zig headers #268

Open
weiznich opened this issue Aug 15, 2024 · 4 comments
Open

Comments

@weiznich
Copy link

I have a project that depends on netcdf-src 0.4.0. Trying to build that in the official rust-lang docker container with cargo-zigbuild 0.19.1 and zig 0.13.0 installed fails with the following error messages:

/opt/zig/lib/libc/include/generic-glibc/stdio.h:878:38: error: expected function body after function declarator
    878 | extern void perror (const char *__s) __COLD;
        |                                      ^
  In file included from /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.4.0/source/libdispatch/dcopy.c:11:
  In file included from /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/netcdf-src-0.4.0/source/include/ncdispatch.h:17:
  /opt/zig/lib/libc/include/generic-glibc/stdio.h:878:38: error: expected function body after function declarator
    878 | extern void perror (const char *__s) __COLD;
        |                                      ^
  1 error generated.
  gmake[2]: *** [libsrc/CMakeFiles/netcdf3.dir/build.make:88: libsrc/CMakeFiles/netcdf3.dir/v1hpg.c.o] Error 1
  gmake[2]: *** Waiting for unfinished jobs....
  1 error generated.
// repeated many times

I can workaround that error by just adding CFLAGS="-D__COLD=\"\"" to the compilation environment. I report this here as this either seems to be an issue in cargo-zigbuild (not setting that option) or in zig itself (__COLD) shouldn't be there.

Interestingly it works outside of the docker container with the same rust, zig, zig-build and netcdf-src version…

@messense
Copy link
Member

messense commented Aug 16, 2024

bminor/glibc@0ab341b

It should have been defined by glibc itself (in glibc 2.38+), can you try to inspect the code of the same file in /opt/zig/lib/libc/include/?

@weiznich
Copy link
Author

Thanks for the response.

I checked it in the rust docker container and it seem like:

  • /opt/zig/lib/libc/include/generic-glibc/sys/cdefs.h does contain the relevant defines
  • /usr/include/x86_64-linux-gnu/sys/cdefs.h does not contain the relevant defines

Also ldd reports that the system uses glibc 2.36

It seems like that for some reason the system header from /usr is used and not the bundled header from zig

For reference that's with the rust:1.80.1 docker image (+ a view custom layers to install zig + cargo-zigbuild)

@messense
Copy link
Member

Maybe it's caused by cmake? There is support for cmake in cargo-zigbuild but it's not really tested thoroughly.

cargo-zigbuild/src/zig.rs

Lines 475 to 486 in d420792

let cmake_toolchain_file_env = format!("CMAKE_TOOLCHAIN_FILE_{env_target}");
if env::var_os(&cmake_toolchain_file_env).is_none()
&& env::var_os(format!("CMAKE_TOOLCHAIN_FILE_{parsed_target}")).is_none()
&& env::var_os("TARGET_CMAKE_TOOLCHAIN_FILE").is_none()
&& env::var_os("CMAKE_TOOLCHAIN_FILE").is_none()
{
if let Ok(cmake_toolchain_file) =
Self::setup_cmake_toolchain(parsed_target, &zig_wrapper, enable_zig_ar)
{
cmd.env(cmake_toolchain_file_env, cmake_toolchain_file);
}
}

@weiznich
Copy link
Author

That might be the case, I'm not sure about that.

As a general note: The project I'm building depends on quite a few complex cmake projects (netcdf, hdf5, gdal, proj, just to name some). It works fine as soon as I specify that additional define manually. I believe that this means the cmake integration should be mostly fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants