Serenity: Build is broken on macOS

Created on 15 May 2020  路  17Comments  路  Source: SerenityOS/serenity

macOS 10.14.6

cd Toolchain
./BuildIt_x86_64.sh
cd ..
mkdir build
cmake ..
make -i
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/FileSystemPath.cpp.o
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/FlyString.cpp.o
^C
bash-5.0$ make -i -j8
[  0%] Building ASM object Kernel/CMakeFiles/boot.dir/Arch/i386/Boot/boot.S.o
/bin/sh: /Users/diver/serenity/Toolchain/Local/bin/i686-pc-serenity-gcc: No such file or directory
[  0%] Building CXX object Libraries/LibC/CMakeFiles/crt0.dir/crt0.cpp.o
[  0%] Building CXX object Kernel/Modules/CMakeFiles/TestModule.dir/TestModule.o
/bin/sh: /Users/diver/serenity/Toolchain/Local/bin/i686-pc-serenity-g++: No such file or directory
/bin/sh: /Users/diver/serenity/Toolchain/Local/bin/i686-pc-serenity-g++: No such file or directory
[  0%] Built target boot
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/FlyString.cpp.o
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/MappedFile.cpp.o
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/LogStream.cpp.o
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/JsonParser.cpp.o
[  0%] Linking CXX static library libcrt0.a
[  0%] Linking CXX static library libTestModule.a
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/JsonValue.cpp.o
Error running link command: No such file or directory
Error running link command: No such file or directory
install: illegal option -- D
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
[  0%] Built target TestModule
[  0%] Built target crt0
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/SharedBuffer.cpp.o
[  0%] Building CXX object Libraries/LibM/CMakeFiles/LibM.dir/math.cpp.o
/bin/sh: /Users/diver/serenity/Toolchain/Local/bin/i686-pc-serenity-g++: No such file or directory

Most helpful comment

I got it to build and run on macOS by splitting the CMake host tools and actual OS building.
I will try to cleanup the patch so that it can be sent as a PR.

Screenshot 2020-06-05 at 23 14 38

All 17 comments

./BuildIt_x86_64.sh hasn't been updated for the CMake build system. Any reason you're not using BuildIt.sh?

cc @bugaevc (:smile:)

Yeah, it sounds like you haven't built the toolchain properly.

Tried again with BuildIt.sh:

make -i
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPServer.cpp.o
/Users/diver/serenity/Libraries/LibCore/TCPServer.cpp:40:42: error: use of undeclared identifier 'SOCK_NONBLOCK'
    m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                         ^
/Users/diver/serenity/Libraries/LibCore/TCPServer.cpp:40:58: error: use of undeclared identifier 'SOCK_CLOEXEC'
    m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                                         ^
2 errors generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPSocket.cpp.o
/Users/diver/serenity/Libraries/LibCore/TCPSocket.cpp:46:44: error: use of undeclared identifier 'SOCK_NONBLOCK'
    int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
                                           ^
1 error generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPServer.cpp.o
/Users/diver/serenity/Libraries/LibCore/UDPServer.cpp:39:41: error: use of undeclared identifier 'SOCK_NONBLOCK'
    m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                        ^
/Users/diver/serenity/Libraries/LibCore/UDPServer.cpp:39:57: error: use of undeclared identifier 'SOCK_CLOEXEC'
    m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                                        ^
2 errors generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPSocket.cpp.o
/Users/diver/serenity/Libraries/LibCore/UDPSocket.cpp:46:43: error: use of undeclared identifier 'SOCK_NONBLOCK'
    int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
                                          ^
1 error generated.
[  0%] Linking CXX static library libLagomCore.a
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPServer.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPSocket.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPServer.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPSocket.cpp.o: No such file or directory
[  3%] Built target LagomCore
[  3%] Linking CXX executable IPCCompiler
ld: archive has no table of contents file '../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target IPCCompiler
[  3%] Linking CXX executable FormCompiler
ld: archive has no table of contents file '../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target FormCompiler
[  3%] Linking CXX executable Generate_CSS_PropertyID_cpp
ld: archive has no table of contents file '../../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target Generate_CSS_PropertyID_cpp
[  3%] Linking CXX executable Generate_CSS_PropertyID_h
ld: archive has no table of contents file '../../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target Generate_CSS_PropertyID_h
[  3%] Linking CXX executable TestOptional
^C
MacBookPro:Build diver$ make -i
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPServer.cpp.o
/Users/diver/serenity/Libraries/LibCore/TCPServer.cpp:40:42: error: use of undeclared identifier 'SOCK_NONBLOCK'
    m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                         ^
/Users/diver/serenity/Libraries/LibCore/TCPServer.cpp:40:58: error: use of undeclared identifier 'SOCK_CLOEXEC'
    m_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                                         ^
2 errors generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPSocket.cpp.o
/Users/diver/serenity/Libraries/LibCore/TCPSocket.cpp:46:44: error: use of undeclared identifier 'SOCK_NONBLOCK'
    int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
                                           ^
1 error generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPServer.cpp.o
/Users/diver/serenity/Libraries/LibCore/UDPServer.cpp:39:41: error: use of undeclared identifier 'SOCK_NONBLOCK'
    m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                        ^
/Users/diver/serenity/Libraries/LibCore/UDPServer.cpp:39:57: error: use of undeclared identifier 'SOCK_CLOEXEC'
    m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
                                                        ^
2 errors generated.
[  0%] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPSocket.cpp.o
/Users/diver/serenity/Libraries/LibCore/UDPSocket.cpp:46:43: error: use of undeclared identifier 'SOCK_NONBLOCK'
    int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
                                          ^
1 error generated.
[  0%] Linking CXX static library libLagomCore.a
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPServer.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/TCPSocket.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPServer.cpp.o: No such file or directory
ar: CMakeFiles/LagomCore.dir/__/__/Libraries/LibCore/UDPSocket.cpp.o: No such file or directory
[  3%] Built target LagomCore
[  3%] Linking CXX executable IPCCompiler
ld: archive has no table of contents file '../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target IPCCompiler
[  3%] Linking CXX executable FormCompiler
ld: archive has no table of contents file '../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target FormCompiler
[  3%] Linking CXX executable Generate_CSS_PropertyID_cpp
ld: archive has no table of contents file '../../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target Generate_CSS_PropertyID_cpp
[  3%] Linking CXX executable Generate_CSS_PropertyID_h
ld: archive has no table of contents file '../../../Meta/Lagom/libLagomCore.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[  3%] Built target Generate_CSS_PropertyID_h
[  3%] Linking CXX executable TestOptional
^C

^ I have a similar (if not the same) error.

I managed to get it to build an image after some nasty hacks but qemu gets stuck in a bootloop. (maybe the same issue as #2108 ?)

The only thing that should probably be merged from this patch is the install -> ginstall stuff, the rest of it needs more "proper" fixes I think.

https://gist.github.com/bear24rw/90e51cd42c4dc79dc14d3217657956cf

To be honest, the install -> ginstall thing is also related to other systems such as FreeBSD, that provide this tool via optional package (in my case, coreutils) but prefix with g to differentiate from non-GNU tools. Adding additional rules per each OS doesn't seem right as it's an unnecessary overhead to maintain.

Instead, I symlinked ginstall to install to solve the issues. Not sure if the same step would apply to macOS, but this was the way to go for me to avoid filling the scripts with host OS-oriented changes.

We could just check if ginstall exists and use that.

Just I have been spending some time to try building everything on macOS from latest master with the new CMake Build System. I've needed to patch things here and there, but the real issue is another.

I don't think it's possible to get it to work unless we split the build process with two separate cmake invocations, with two separate cmake directories, one for support host tools (that must be compiled with host compiler) and one for the OS using serenity's GCC cross-compiler.

The trick of setting set(CMAKE_C_COMPILER) & company at a later stage of the root CMake script, after building host tools, doesn't work on macOS because once the root project() is called, it will set options like -isysroot and -mmacosx-version-min even when using serenity's GCC, that of course will complain about the unknown option and fail.

I'm not a CMake expert, but from what I've read, the best solution is to split the compilation in two invocations (or use ExternalProjects or something like that).
I've not found a way to remove or overwrite such "auto-detected" cxx flags at later stages. CMake is appending them at the end of CMAKE_CXX_FLAGS no matter what I am doing.

MacBookPro:build diver$ make
[  3%] Built target LagomCore
[  4%] Built target IPCCompiler
[  4%] Built target FormCompiler
[  4%] Built target Generate_CSS_PropertyID_cpp
[  5%] Built target Generate_CSS_PropertyID_h
[  5%] Built target TestOptional
[  5%] Built target TestWeakPtr
[  6%] Built target TestVector
[  6%] Built target TestCircularDeque
[  6%] Built target TestJSON
[  6%] Built target TestUtf8
[  6%] Built target TestURL
[  6%] Built target TestString
[  6%] Built target TestNonnullRefPtr
[  7%] Built target TestHashMap
[  7%] Built target TestFixedArray
[  7%] Built target TestStringUtils
[  7%] Built target TestStringView
[  7%] Built target TestFileSystemPath
[  7%] Built target TestAtomic
[  7%] Built target TestQueue
[  7%] Built target TestCircularQueue
[  8%] Built target TestRefPtr
[  9%] Built target TestBitmap
[  9%] Built target TestBinarySearch
[  9%] Built target boot
[  9%] Building CXX object Kernel/CMakeFiles/Kernel.dir/ACPI/DMIDecoder.cpp.o
In file included from /Users/diver/serenity/./Kernel/ACPI/DMIDecoder.h:31,
                 from /Users/diver/serenity/Kernel/ACPI/DMIDecoder.cpp:28:
/Users/diver/serenity/./AK/Vector.h:40:14: fatal error: initializer_list: No such file or directory
   40 | #    include <initializer_list>
      |              ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Kernel/CMakeFiles/Kernel.dir/ACPI/DMIDecoder.cpp.o] Error 1
make[1]: *** [Kernel/CMakeFiles/Kernel.dir/all] Error 2
make: *** [all] Error 2

After removing the DynamicLink Demo from the build (and dealing with the ginstall goodness), I was able to get to make install, where stderr is flooded with errors all similar to:

error: .../usr/bin/install_name_tool: input file: .../serenity/Build/Root/bin/whoami is not a Mach-O file

Attempting to build and run an image results in a loop of triple faults within QEMU.

I got it to build and run on macOS by splitting the CMake host tools and actual OS building.
I will try to cleanup the patch so that it can be sent as a PR.

Screenshot 2020-06-05 at 23 14 38

I have been pushing my fork.

https://github.com/Pagghiu/serenity/tree/build-macos-2

I am still waiting to create a PR because I need to check if the regular Linux build still works, and I don't have an handy VM ready for it.

@Pagghiu would the CI build not tell you that?

@Pagghiu would the CI build not tell you that?

I was not sure about it because I've been spotting the caching system that tries to skip building the Toolchain when there is no change in the dependencies, using some hashing.
I am not sure if changes to the CMake in LibC build (that I've done) would cause a rebuild of the toolchain in the CI.
I've been taking some time to test it under a fresh Ubuntu 2020.04 VM anyway 馃槈

Not sure what the state of the macOS build is, but there's no activity here for a long time so I'm just gonna close this.
We can always open new issues if there are new problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xTibor picture xTibor  路  5Comments

MWGuy picture MWGuy  路  4Comments

nvella picture nvella  路  6Comments

nvella picture nvella  路  7Comments

nibblebits picture nibblebits  路  4Comments