From dabfaef44438d7fc2c4d4b1742c8b13001c10a20 Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 15 Nov 2023 19:50:43 +0200 Subject: tests.cc-wrapper: add atomics test `-std=c++17` is for clang 5 --- pkgs/test/cc-wrapper/atomics.cc | 8 ++++++++ pkgs/test/cc-wrapper/default.nix | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pkgs/test/cc-wrapper/atomics.cc (limited to 'pkgs/test/cc-wrapper') diff --git a/pkgs/test/cc-wrapper/atomics.cc b/pkgs/test/cc-wrapper/atomics.cc new file mode 100644 index 0000000000000..23601ae92f0b0 --- /dev/null +++ b/pkgs/test/cc-wrapper/atomics.cc @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + std::atomic_int x = {0}; + return !std::atomic_is_lock_free(&x); +} diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix index 74009c97980d2..a0088751d4a24 100644 --- a/pkgs/test/cc-wrapper/default.nix +++ b/pkgs/test/cc-wrapper/default.nix @@ -9,7 +9,8 @@ let ); staticLibc = lib.optionalString (stdenv.hostPlatform.libc == "glibc") "-L ${glibc.static}/lib"; emulator = stdenv.hostPlatform.emulator buildPackages; - libcxxStdenvSuffix = lib.optionalString (stdenv.cc.libcxx != null) "-libcxx"; + isCxx = stdenv.cc.libcxx != null; + libcxxStdenvSuffix = lib.optionalString isCxx "-libcxx"; in stdenv.mkDerivation { pname = "cc-wrapper-test-${stdenv.cc.cc.pname}${libcxxStdenvSuffix}"; version = stdenv.cc.version; @@ -37,6 +38,14 @@ in stdenv.mkDerivation { $CXX -o include-cxxabi ${./include-cxxabi.cc} ${emulator} ./include-cxxabi + # cxx doesn't have libatomic.so + ${lib.optionalString (!isCxx) '' + # https://github.com/NixOS/nixpkgs/issues/91285 + echo "checking whether libatomic.so can be linked... " >&2 + $CXX -shared -o atomics.so ${./atomics.cc} -latomic ${lib.optionalString (stdenv.cc.isClang && lib.versionOlder stdenv.cc.version "6.0.0" ) "-std=c++17"} + $READELF -d ./atomics.so | grep libatomic.so && echo "ok" >&2 || echo "failed" >&2 + ''} + ${lib.optionalString (stdenv.isDarwin && stdenv.cc.isClang) '' echo "checking whether compiler can build with CoreFoundation.framework... " >&2 mkdir -p foo/lib -- cgit 1.4.1