diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 249463f391..0c2e978a92 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -48,7 +48,7 @@ jobs: # This assumes that *ALL* LibC headers have an impact on the Toolchain. # This is wrong, and causes more Toolchain rebuilds than necessary. # However, we want to avoid false cache hits at all costs. - key: ${{ runner.os }}-toolchain-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch') }} + key: ${{ runner.os }}-toolchain-i686-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }} - name: Restore or regenerate Toolchain run: TRY_USE_LOCAL_TOOLCHAIN=y ${{ github.workspace }}/Toolchain/BuildIt.sh @@ -155,7 +155,7 @@ jobs: # This assumes that *ALL* LibC headers have an impact on the Toolchain. # This is wrong, and causes more Toolchain rebuilds than necessary. # However, we want to avoid false cache hits at all costs. - key: ${{ runner.os }}-toolchain-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch') }} + key: ${{ runner.os }}-toolchain-i686-${{ hashFiles('Libraries/LibC/**/*.h', 'Toolchain/Patches/*.patch', 'Toolchain/BuildIt.sh') }} - name: Restore or regenerate Toolchain run: TRY_USE_LOCAL_TOOLCHAIN=y ${{ github.workspace }}/Toolchain/BuildIt.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a404076f3..05dec4169b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ enable_testing() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(SERENITY_ARCH "i686" CACHE STRING "Target architecture for SerenityOS.") + add_custom_target(run COMMAND ${CMAKE_SOURCE_DIR}/Meta/run.sh USES_TERMINAL @@ -23,12 +25,12 @@ add_custom_target(image DEPENDS qemu-image ) add_custom_target(qemu-image - COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/Meta/build-image-qemu.sh + COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-qemu.sh BYPRODUCTS ${CMAKE_BINARY_DIR}/_disk_image USES_TERMINAL ) add_custom_target(grub-image - COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/Meta/build-image-grub.sh + COMMAND ${CMAKE_COMMAND} -E env "SERENITY_ROOT=${CMAKE_SOURCE_DIR}" "SERENITY_ARCH=${SERENITY_ARCH}" ${CMAKE_SOURCE_DIR}/Meta/build-image-grub.sh BYPRODUCTS ${CMAKE_BINARY_DIR}/grub_disk_image USES_TERMINAL ) @@ -79,8 +81,8 @@ set(CMAKE_STAGING_PREFIX ${CMAKE_BINARY_DIR}/Root) set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Root) set(CMAKE_INSTALL_DATAROOTDIR ${CMAKE_BINARY_DIR}/Root/res) -set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/Toolchain/Local/bin) -set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/i686-pc-serenity-) +set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/Toolchain/Local/${SERENITY_ARCH}/bin) +set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/${SERENITY_ARCH}-pc-serenity-) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) diff --git a/Documentation/UsingQtCreator.md b/Documentation/UsingQtCreator.md index c2d7e662c6..3535170fd2 100644 --- a/Documentation/UsingQtCreator.md +++ b/Documentation/UsingQtCreator.md @@ -15,7 +15,7 @@ First, make sure you have a working toolchain and can build and run SerenityOS. * Edit the `serenity.config` file (In Qt Creator, hit ^K or CMD+K on a Mac to open the search dialog, type the name of the file and hit return to open it) * Add the following `#define`s to the file: `DEBUG`, `SANITIZE_PTRS`, and `KERNEL`. Depending on what you are working on, you need to have that last define commented out. If you're planning on working in the userland, comment out `#define KERNEL`. If you're working on the Kernel, then uncomment `#define KERNEL`. * Edit the `serenity.cxxflags` file to say `-std=c++2a -m32` -* Edit the `serenity.includes` file, add the following lines: `.`, `..`, `../..`, `Services/`, `Libraries/`, `Libraries/LibC/`, `Libraries/LibPthread/`, `Libraries/LibM/`, `Toolchain/Local/i686-pc-serenity/include/c++/10.2.0`, `Build/Services/`, `Build/Libraries/`, `AK/` +* Edit the `serenity.includes` file, add the following lines: `.`, `..`, `../..`, `Services/`, `Libraries/`, `Libraries/LibC/`, `Libraries/LibPthread/`, `Libraries/LibM/`, `Toolchain/Local/i686/i686-pc-serenity/include/c++/10.2.0`, `Build/Services/`, `Build/Libraries/`, `AK/` Qt Creator should be set up correctly now, go ahead and explore the project and try making changes. Have fun! :^) @@ -42,4 +42,4 @@ You may want to read up what `git add -p` does (or `git checkout -p`, to undo). ## Compiler Kits You can slightly improve how well Qt interprets the code by adding and setting up an appropriate "compiler kit". -For that you will need to reference the compilers at `Toolchain/Local/bin/i686-pc-serenity-gcc` and `Toolchain/Local/bin/i686-pc-serenity-g++`. +For that you will need to reference the compilers at `Toolchain/Local/i686/bin/i686-pc-serenity-gcc` and `Toolchain/Local/i686/bin/i686-pc-serenity-g++`. diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 46e55fe30d..5a8667b2d8 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -274,10 +274,10 @@ file(GENERATE OUTPUT linker.ld INPUT linker.ld) if (${CMAKE_HOST_SYSTEM_NAME} MATCHES SerenityOS) include_directories(/usr/local/include/c++/10.2.0/) - include_directories(/usr/local/include/c++/10.2.0/i686-pc-serenity/) + include_directories(/usr/local/include/c++/10.2.0/${SERENITY_ARCH}-pc-serenity/) else() - include_directories(../Toolchain/Local/i686-pc-serenity/include/c++/10.2.0/) - include_directories(../Toolchain/Local/i686-pc-serenity/include/c++/10.2.0/i686-pc-serenity/) + include_directories(../Toolchain/Local/${SERENITY_ARCH}/${SERENITY_ARCH}-pc-serenity/include/c++/10.2.0/) + include_directories(../Toolchain/Local/${SERENITY_ARCH}/${SERENITY_ARCH}-pc-serenity/include/c++/10.2.0/${SERENITY_ARCH}-pc-serenity/) endif() add_executable(Kernel ${SOURCES}) diff --git a/Meta/CLion/CMakeLists.txt b/Meta/CLion/CMakeLists.txt index f0161cc960..82a60501bf 100644 --- a/Meta/CLion/CMakeLists.txt +++ b/Meta/CLion/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0) project(serenity) set(CMAKE_CXX_STANDARD 20) +set(SERENITY_ARCH "i686" CACHE STRING "Target architecture for SerenityOS.") + file(GLOB_RECURSE AK_SOURCES "serenity/AK/*.cpp") file(GLOB_RECURSE APPLICATIONS_SOURCES "serenity/Applications/*.cpp") file(GLOB_RECURSE BASE_SOURCES "serenity/Base/*.cpp") @@ -26,7 +28,7 @@ set(INCLUDE_DIRS "serenity/Libraries/LibPthread" "serenity/Libraries/LibM" "serenity/Services" - "serenity/Toolchain/Local/i686-pc-serenity/include/c++/10.2.0" + "serenity/Toolchain/Local/${SERENITY_ARCH}/${SERENITY_ARCH}-pc-serenity/include/c++/10.2.0" "serenity/Build/Services" "serenity/Build/Libraries") diff --git a/Meta/build-root-filesystem.sh b/Meta/build-root-filesystem.sh index d2894e00d1..6a1487f9da 100755 --- a/Meta/build-root-filesystem.sh +++ b/Meta/build-root-filesystem.sh @@ -33,7 +33,7 @@ umask 0022 printf "installing base system... " $CP -PdR "$SERENITY_ROOT"/Base/* mnt/ -$CP "$SERENITY_ROOT"/Toolchain/Local/i686-pc-serenity/lib/libgcc_s.so mnt/usr/lib/ +$CP "$SERENITY_ROOT"/Toolchain/Local/i686/i686-pc-serenity/lib/libgcc_s.so mnt/usr/lib/ $CP -PdR Root/* mnt/ # If umask was 027 or similar when the repo was cloned, # file permissions in Base/ are too restrictive. Restore diff --git a/Ports/.port_include.sh b/Ports/.port_include.sh index 90c4e9495a..974da4eb5b 100755 --- a/Ports/.port_include.sh +++ b/Ports/.port_include.sh @@ -7,7 +7,7 @@ prefix=$SERENITY_ROOT/Ports export CC=i686-pc-serenity-gcc export CXX=i686-pc-serenity-g++ -export PATH=$SERENITY_ROOT/Toolchain/Local/bin:$PATH +export PATH=$SERENITY_ROOT/Toolchain/Local/i686/bin:$PATH MD5SUM=md5sum diff --git a/Toolchain/BuildIt.sh b/Toolchain/BuildIt.sh index bcbd1cc976..cfa9744a6e 100755 --- a/Toolchain/BuildIt.sh +++ b/Toolchain/BuildIt.sh @@ -11,7 +11,7 @@ echo "$DIR" ARCH=${ARCH:-"i686"} TARGET="$ARCH-pc-serenity" -PREFIX="$DIR/Local" +PREFIX="$DIR/Local/$ARCH" BUILD=$(realpath "$DIR/../Build") SYSROOT="$BUILD/Root" @@ -179,14 +179,14 @@ popd # === COMPILE AND INSTALL === mkdir -p "$PREFIX" -mkdir -p "$DIR/Build/binutils" -mkdir -p "$DIR/Build/gcc" +mkdir -p "$DIR/Build/$ARCH/binutils" +mkdir -p "$DIR/Build/$ARCH/gcc" if [ -z "$MAKEJOBS" ]; then MAKEJOBS=$($NPROC) fi -pushd "$DIR/Build/" +pushd "$DIR/Build/$ARCH" unset PKG_CONFIG_LIBDIR # Just in case pushd binutils @@ -251,7 +251,7 @@ pushd "$DIR/Build/" "$MAKE" install-target-libstdc++-v3 || exit 1 if [ "$(uname -s)" = "OpenBSD" ]; then - cd "$DIR/Local/libexec/gcc/i686-pc-serenity/$GCC_VERSION" && ln -sf liblto_plugin.so.0.0 liblto_plugin.so + cd "$DIR/Local/libexec/gcc/$TARGET/$GCC_VERSION" && ln -sf liblto_plugin.so.0.0 liblto_plugin.so fi popd diff --git a/Toolchain/BuildIt_x86_64.sh b/Toolchain/BuildIt_x86_64.sh deleted file mode 100755 index 71b1be56b5..0000000000 --- a/Toolchain/BuildIt_x86_64.sh +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env bash -set -e - -# This file will need to be run in bash, for now. - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -echo "$DIR" - -ARCH=${ARCH:-"x86_64"} -TARGET="$ARCH-pc-serenity" -PREFIX="$DIR/Local/x86_64" -SYSROOT="$DIR/../Root" - -MAKE="make" -MD5SUM="md5sum" -NPROC="nproc" - -if [ "$(uname -s)" = "OpenBSD" ]; then - MAKE=gmake - MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpuonline" - export CC=egcc - export CXX=eg++ - export with_gmp=/usr/local - export LDFLAGS=-Wl,-z,notext -elif [ "$(uname -s)" = "FreeBSD" ]; then - MAKE=gmake - MD5SUM="md5 -q" - NPROC="sysctl -n hw.ncpu" - export with_gmp=/usr/local - export with_mpfr=/usr/local -fi - -echo PREFIX is "$PREFIX" -echo SYSROOT is "$SYSROOT" - -mkdir -p "$DIR/Tarballs" - -BINUTILS_VERSION="2.33.1" -BINUTILS_MD5SUM="1a6b16bcc926e312633fcc3fae14ba0a" -BINUTILS_NAME="binutils-$BINUTILS_VERSION" -BINUTILS_PKG="${BINUTILS_NAME}.tar.gz" -BINUTILS_BASE_URL="http://ftp.gnu.org/gnu/binutils" - -GCC_VERSION="10.1.0" -GCC_MD5SUM="8a9fbd7e24d04c5d36e96bc894d3cd6b" -GCC_NAME="gcc-$GCC_VERSION" -GCC_PKG="${GCC_NAME}.tar.gz" -GCC_BASE_URL="http://ftp.gnu.org/gnu/gcc" - -pushd "$DIR/Tarballs" - md5="$($MD5SUM $BINUTILS_PKG | cut -f1 -d' ')" - echo "bu md5='$md5'" - if [ ! -e $BINUTILS_PKG ] || [ "$md5" != ${BINUTILS_MD5SUM} ] ; then - rm -f $BINUTILS_PKG - curl -LO "$BINUTILS_BASE_URL/$BINUTILS_PKG" - else - echo "Skipped downloading binutils" - fi - - md5="$($MD5SUM ${GCC_PKG} | cut -f1 -d' ')" - echo "gc md5='$md5'" - if [ ! -e $GCC_PKG ] || [ "$md5" != ${GCC_MD5SUM} ] ; then - rm -f $GCC_PKG - curl -LO "$GCC_BASE_URL/$GCC_NAME/$GCC_PKG" - else - echo "Skipped downloading gcc" - fi - - if [ ! -d ${BINUTILS_NAME} ]; then - echo "Extracting binutils..." - tar -xzf ${BINUTILS_PKG} - - pushd ${BINUTILS_NAME} - git init >/dev/null - git add . >/dev/null - git commit -am "BASE" >/dev/null - git apply "$DIR"/Patches/binutils.patch >/dev/null - popd - else - echo "Skipped extracting binutils" - fi - - if [ ! -d $GCC_NAME ]; then - echo "Extracting gcc..." - tar -xzf $GCC_PKG - - pushd $GCC_NAME - git init >/dev/null - git add . >/dev/null - git commit -am "BASE" >/dev/null - git apply "$DIR"/Patches/gcc.patch >/dev/null - popd - else - echo "Skipped extracting gcc" - fi - - if [ "$(uname)" = "Darwin" ]; then - pushd "gcc-${GCC_VERSION}" - ./contrib/download_prerequisites - popd - fi - -popd - -mkdir -p "$PREFIX" - -mkdir -p "$DIR/Build/x86_64/binutils" -mkdir -p "$DIR/Build/x86_64/gcc" - -if [ -z "$MAKEJOBS" ]; then - MAKEJOBS=$($NPROC) -fi - -pushd "$DIR/Build/x86_64" - unset PKG_CONFIG_LIBDIR # Just in case - - pushd binutils - rm -f ./config.cache # Let's do this in case someone has already built the i686 version - "$DIR"/Tarballs/binutils-2.33.1/configure --prefix="$PREFIX" \ - --target="$TARGET" \ - --with-sysroot="$SYSROOT" \ - --enable-shared \ - --disable-nls || exit 1 - if [ "$(uname)" = "Darwin" ]; then - # under macOS generated makefiles are not resolving the "intl" - # dependency properly to allow linking its own copy of - # libintl when building with --enable-shared. - "$MAKE" -j "$MAKEJOBS" || true - pushd intl - "$MAKE" all-yes - popd - fi - "$MAKE" -j "$MAKEJOBS" || exit 1 - "$MAKE" install || exit 1 - popd - - pushd gcc - if [ "$(uname -s)" = "OpenBSD" ]; then - perl -pi -e 's/-no-pie/-nopie/g' "$DIR/Tarballs/gcc-$GCC_VERSION/gcc/configure" - fi - - "$DIR/Tarballs/gcc-$GCC_VERSION/configure" --prefix="$PREFIX" \ - --target="$TARGET" \ - --with-sysroot="$SYSROOT" \ - --disable-nls \ - --with-newlib \ - --enable-shared \ - --enable-languages=c,c++ || exit 1 - - echo "XXX build gcc and libgcc" - "$MAKE" -j "$MAKEJOBS" all-gcc all-target-libgcc || exit 1 - echo "XXX install gcc and libgcc" - "$MAKE" install-gcc install-target-libgcc || exit 1 - - echo "XXX serenity libc and libm" - ( cd "$DIR/../Libraries/LibC/" && "$MAKE" clean && "$MAKE" EXTRA_LIBC_DEFINES="-DBUILDING_SERENITY_TOOLCHAIN" && "$MAKE" install ) - ( cd "$DIR/../Libraries/LibM/" && "$MAKE" clean && "$MAKE" && "$MAKE" install ) - - echo "XXX build libstdc++" - "$MAKE" all-target-libstdc++-v3 || exit 1 - echo "XXX install libstdc++" - "$MAKE" install-target-libstdc++-v3 || exit 1 - - if [ "$(uname -s)" = "OpenBSD" ]; then - cd "$DIR/Local/libexec/gcc/x86_64-pc-serenity/$GCC_VERSION" && ln -sf liblto_plugin.so.0.0 liblto_plugin.so - fi - popd -popd - diff --git a/Toolchain/BuildPython.sh b/Toolchain/BuildPython.sh index 5da3b33b51..71c89babc9 100755 --- a/Toolchain/BuildPython.sh +++ b/Toolchain/BuildPython.sh @@ -7,9 +7,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo "$DIR" -TARGET=i686-pc-serenity -PREFIX="$DIR/Local" -SYSROOT="$DIR/../Root" +ARCH=${ARCH:-"i686"} +TARGET="$ARCH-pc-serenity" +PREFIX="$DIR/Local/$ARCH" +BUILD=$(realpath "$DIR/../Build") +SYSROOT="$BUILD/Root" source "$DIR/../Ports/python-3.6/version.sh" @@ -45,13 +47,13 @@ pushd "$DIR/Tarballs" popd mkdir -p "$PREFIX" -mkdir -p "$DIR/Build/python" +mkdir -p "$DIR/Build/$ARCH/python" if [ -z "$MAKEJOBS" ]; then MAKEJOBS=$(nproc) fi -pushd "$DIR/Build/" +pushd "$DIR/Build/$ARCH" pushd python "$DIR"/Tarballs/Python-$PYTHON_VERSION/configure --prefix="$PREFIX" || exit 1 make -j "$MAKEJOBS" || exit 1 diff --git a/Toolchain/BuildQemu.sh b/Toolchain/BuildQemu.sh index d6c5598ae2..42fa251068 100755 --- a/Toolchain/BuildQemu.sh +++ b/Toolchain/BuildQemu.sh @@ -7,9 +7,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo "$DIR" -TARGET=i686-pc-serenity -PREFIX="$DIR/Local" -SYSROOT="$DIR/../Root" +ARCH=${ARCH:-"i686"} +TARGET="$ARCH-pc-serenity" +PREFIX="$DIR/Local/$ARCH" +BUILD=$(realpath "$DIR/../Build") +SYSROOT="$BUILD/Root" QEMU300_MD5SUM="6a5c8df583406ea24ef25b239c3243e0" QEMU410_MD5SUM="cdf2b5ca52b9abac9bacb5842fa420f8" @@ -46,7 +48,7 @@ pushd "$DIR/Tarballs" popd mkdir -p "$PREFIX" -mkdir -p "$DIR/Build/qemu" +mkdir -p "$DIR/Build/$ARCH/qemu" if [ -z "$MAKEJOBS" ]; then MAKEJOBS=$(nproc) @@ -61,7 +63,7 @@ fi echo Using $UI_LIB based UI -pushd "$DIR/Build/" +pushd "$DIR/Build/$ARCH" pushd qemu "$DIR"/Tarballs/$QEMU_VERSION/configure --prefix="$PREFIX" \ --target-list=i386-softmmu \ diff --git a/Toolchain/CMakeToolchain.txt b/Toolchain/CMakeToolchain.txt index 36e0bf58a7..f7cfa6d029 100644 --- a/Toolchain/CMakeToolchain.txt +++ b/Toolchain/CMakeToolchain.txt @@ -1,5 +1,9 @@ set(CMAKE_SYSTEM_NAME Generic) +if (NOT DEFINED ENV{SERENITY_ARCH}) + message(FATAL_ERROR "SERENITY_ARCH not set.") +endif() + if (NOT DEFINED ENV{SERENITY_ROOT}) message(FATAL_ERROR "SERENITY_ROOT not set.") endif() @@ -12,8 +16,8 @@ set(CMAKE_STAGING_PREFIX $ENV{SERENITY_ROOT}/Build/Root/usr) set(CMAKE_INSTALL_PREFIX $ENV{SERENITY_ROOT}/Build/Root/usr) set(CMAKE_INSTALL_DATAROOTDIR $ENV{SERENITY_ROOT}/Build/Root/usr/share) -set(CMAKE_C_COMPILER i686-pc-serenity-gcc) -set(CMAKE_CXX_COMPILER i686-pc-serenity-g++) +set(CMAKE_C_COMPILER ENV{SERENITY_ARCH}-pc-serenity-gcc) +set(CMAKE_CXX_COMPILER ENV{SERENITY_ARCH}-pc-serenity-g++) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)