tpoechtrager / osxcross

Mac OS X cross toolchain for Linux, FreeBSD, OpenBSD and Android (Termux)
GNU General Public License v2.0
2.91k stars 329 forks source link

"cannot find clang intrinsic headers" on NixOS #342

Open au-phiware opened 2 years ago

au-phiware commented 2 years ago

When running ./build.sh I encounter these messages:

testing x86_64h-apple-darwin21.1-clang ... osxcross: warning: cannot find clang intrinsic headers; please report this issue to the OSXCross project
clang-7: warning: argument unused during compilation: '-arch x86_64h' [-Wunused-command-line-argument]
works
testing x86_64h-apple-darwin21.1-clang++ ... osxcross: warning: cannot find clang intrinsic headers; please report this issue to the OSXCross project
/nix/store/8x25mhcdrnglaj55n80w8pnkwaqcp3sw-binutils-2.35.2/bin/ld: cannot find -lc++

Under the following flake:

{
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
  };

  outputs = {
    self,
    nixpkgs,
    flake-utils,
    ...
  }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
        };

        crateName = "osxcross";

      in with pkgs; rec {
        devShell = mkShell rec {
          buildInputs = [
            clang
            gcc
            llvm
            zlib
            lzma
            libxml2
            bzip2
            openssl
          ];
          packages = [
            curl
            pkg-config
            cmake
            git
            patch
            python3
          ];
          LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
          shellHook =
            ''
              export PATH="$PWD/target/bin:$PATH" \
                INSTALLPREFIX="$PWD/target" \
                LD_LIBRARY_PATH="$PWD/target/lib:$LD_LIBRARY_PATH"
              unset CC CXX
            '';
        };
      });
}

Any advice that you can provide would be greatly appreciated.

au-phiware commented 2 years ago

I think I've realised what the problem is... osxcross appears to be using the path of the clang binary as the basis of its search for the xmmintrin header file (see findClangIntrinsicHeaders). On NixOS systems the clang binary lives in the nix store under the clang-wrapper derivation (e.g. /nix/store/a6i45q9psdn8w4148747k2zj7x8vr6fy-clang-wrapper-7.1.0/bin/clang) and the xmmintrin header lives under the clang derivation (e.g. /nix/store/v5561mfq0y21l0wqj83gf72j4iv3xcz4-clang-7.1.0-lib/lib/clang/7.1.0/include/xmmintrin.h). The wrapper derivation does have a link to the clang derivation but only to it's include directory.

It would be great if we could configure osxcross with the correct directory to the xmmintrin headers.

Now that I know what the problem is I can work around it.