SPMDestinations / homebrew-tap

Homebrew Formulas to install Swift Cross Compilers on macOS (e.g. targeting Ubuntu).
35 stars 2 forks source link

C++ code doesn't compile yet, headers not found (e.g. SPM itself) #4

Open helje5 opened 4 years ago

helje5 commented 4 years ago
git clone https://github.com/apple/swift-package-manager.git
cd swift-package-manager
git checkout release/5.3
swift build -c release --destination \
  /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/destination.json

Gives

In file included from /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Support/raw_ostream.cpp:14:
In file included from /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/Support/raw_ostream.h:17:
In file included from /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/SmallVector.h:17:
/Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Support/include/llvm/ADT/iterator_range.h:22:10: fatal error: 'iterator' file not found
#include <iterator>
         ^~~~~~~~~~
helje5 commented 4 years ago

One would think it is part of the libstdc++-5-dev package, but maybe it is not.

helje5 commented 4 years ago

It is

root@afca478e1ba9:/# dpkg -S /usr/include/c++/5/parallel/iterator.h
libstdc++-5-dev:amd64: /usr/include/c++/5/parallel/iterator.h
helje5 commented 4 years ago

Getting closer to get this working, but it still fails, presumably because the host compiler attempts to lookup the headers in a different location (not "c++/5").

helje5 commented 4 years ago

Sample call which fails (looks basically correct, but the -sdk is missing):

/Users/helge/dev/Swift/SPMDestinations/buildscripts/ubuntu16.04/.build/swift-5.3-ubuntu16.04.xtoolchain/swift.xctoolchain/usr/bin/clang \
  -target x86_64-unknown-linux \
  --sysroot /Users/helge/dev/Swift/SPMDestinations/buildscripts/ubuntu16.04/.build/swift-5.3-ubuntu16.04.xtoolchain/x86_64-ubuntu16.04.sdk \
  -fPIC -g -O0 -DSWIFT_PACKAGE=1 -DDEBUG=1 -fblocks -fmodules -fmodule-name=libllbuild \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/products/libllbuild/include \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/BuildSystem/include \
  -fmodule-map-file=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/llbuildBuildSystem.build/module.modulemap \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/Core/include \
  -fmodule-map-file=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/llbuildCore.build/module.modulemap \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/Basic/include \
  -fmodule-map-file=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/llbuildBasic.build/module.modulemap \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Support/include \
  -fmodule-map-file=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/llvmSupport.build/module.modulemap \
  -I /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/lib/llvm/Demangle/include \
  -fmodule-map-file=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/llvmDemangle.build/module.modulemap \
  -fmodules-cache-path=/Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/ModuleCache \
  -MD -MT dependencies \
  -MF /Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/libllbuild.build/BuildKey-C-API.cpp.d \
  -std=c++14 \
  -c /Users/helge/tmp/swift-package-manager/.build/checkouts/swift-llbuild/products/libllbuild/BuildKey-C-API.cpp \
  -o /Users/helge/tmp/swift-package-manager/.build/x86_64-unknown-linux/debug/libllbuild.build/BuildKey-C-API.cpp.o
helje5 commented 4 years ago

The compilation can be fixed by adding a -I to the clang invocation. However, it doesn't work that way w/ the destination.json:

    "extra-cpp-flags": [
        "-I", "/Users/helge/dev/Swift/SPMDestinations/buildscripts/ubuntu16.04/.build/swift-5.3-ubuntu16.04.xtoolchain/swift.xctoolchain/usr/include/c++/v1",
        "-lstdc++"
    ]

The problem is that extra-cpp-flags are LINKER flags, not C PreProcessor flags nor C++ specific flags. I don't know where clang is looking here by default, it's all linked up in both locations. Damn you SIP ...