SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
29.32k stars 3.13k forks source link

Build issue on macOS: _ctermid.h: No such file or directory #4838

Closed diversys closed 3 years ago

diversys commented 3 years ago

I recently updated host gcc from 10.2.0 to 10.2.0_2 via brew upgrade so it might have something to do with it but I can't really tell. However, now when I try to make a clean build gcc can't find _ctermid.h I already tried brew doctor and brew reinstall gcc to no avail.

cd Toolchain
rm -rf ../Build Build Local Tarballs
./BuildIt.sh
cd ../Build
cmake .. -DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10 -G Ninja
git pull && ninja install && ninja image && ninja run
Already up to date.
[0/2] Re-checking globbed directories...
[222/2345] Building CXX object Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o
FAILED: Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o
/usr/local/bin/g++-10  -I../Libraries -I../. -I../Meta/Lagom/../.. -I../Meta/Lagom/../../Libraries -Wno-unknown-warning-option -O2 -Wall -Wextra -Werror -std=c++2a -fPIC -g -Wno-deprecated-copy -Wno-expansion-to-defined -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -Wformat=2 -fdiagnostics-color=always -ftls-model=initial-exec -fconcepts -std=c++2a -MD -MT Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o -MF Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o.d -o Meta/Lagom/CMakeFiles/LagomCore.dir/__/__/AK/Base64.cpp.o -c ../AK/Base64.cpp
In file included from .././AK/Format.h:35,
                 from .././AK/LogStream.h:29,
                 from .././AK/NonnullRefPtr.h:31,
                 from .././AK/ByteBuffer.h:29,
                 from .././AK/Base64.h:29,
                 from ../AK/Base64.cpp:28:
/usr/local/Cellar/gcc/10.2.0_2/lib/gcc/10/gcc/x86_64-apple-darwin18/10.2.0/include-fixed/stdio.h:219:10: fatal error: _ctermid.h: No such file or directory
  219 | #include <_ctermid.h>
      |          ^~~~~~~~~~~~
compilation terminated.
brew info gcc
gcc: stable 10.2.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/10.2.0_2 (1,465 files, 338.7MB) *
  Poured from bottle on 2021-01-07 at 11:59:53
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gcc.rb
License: GPL-3.0
==> Dependencies
Required: gmp ✔, isl ✔, libmpc ✔, mpfr ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 106,567 (30 days), 279,372 (90 days), 1,205,541 (365 days)
install-on-request: 52,551 (30 days), 131,007 (90 days), 570,700 (365 days)
build-error: 0 (30 days)
ccapitalK commented 3 years ago

Uh, it appears that you are trying to build Serenity with your system's gcc installation. SerenityOS requires a custom version of gcc tuned to compile using serenity-specific internal compiler options, which is a standard practice in the osdev world. This custom version is what is built when you build the Toolchain. Is there any particular reason why you are trying to use your own gcc version?

If not, I believe simply not using the -DCMAKE_CXX_COMPILER=gcc-10 and -DCMAKE_C_COMPILER=g++-10 flags when running cmake will fix your build issues. If you look closely, it shows that the compiler is trying to include your system's version of stdio.h when compiling AK, which is incompatible with how SerenityOS implements stdio.h.

diversys commented 3 years ago

Yeah, I understand that Serenity uses its own version of gcc. These cmake flags are mentioned in https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md#macos-prerequisites and this is how I always used to configure in the past and it always worked.

ccapitalK commented 3 years ago

Hmm, I was not aware of that. Looking further into the reasoning behind that, it appears that it's because tools like IPCCompiler need to be built using the system's compiler, according to #4594, so overriding the CMAKE_CXX_COMPILER flag is surprisingly legit.

The only cause I can think of is that something in your system compiler is broken, if it's reliable enough to compile the toolchain maybe it's some weird edge case that's only triggered when header files are included in a specific order or something? I've found a kind of similar issue at https://stackoverflow.com/questions/58085311/stdio-fatal-error-ctermid-h-file-not-found , but other than that, I'm not sure whether this is an issue with SerenityOS or your compiler.

ADKaster commented 3 years ago

Right there are a bunch of host tools that need built and run as part of a normal serenity build. There's the IPC compiler and a few code generators for LibWeb that need to use the host compiler to compile and execute some programs at build time.

The current MacOs CI doesn't use gcc 10.2.0_02, it uses 10.2.0 https://github.com/SerenityOS/serenity/runs/1661911737?check_suite_focus=true#step:4:11

This is another reason to switch to proper two phase cmake builds per #4594. Though, overriding CMAKE_CXX_COMPILER within the cmake lists is not "surprisingly legit", more "surprising that it works at all".

diversys commented 3 years ago

I downgraded gcc to 10.2.0 and isl to 0.22 and that fixed the build.