summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-07-21 19:16:46 +0200
committerLéo Lam <leo@leolam.fr>2021-07-21 22:26:11 +0200
commit8cf3dd776bf5a839f9941059ccb7b28e27c6791f (patch)
treed6cae2d5d797968b8caebb75f88c54a315b02f6c
parent1c8152de2228a7011852d0bdd69c397ea8692fd3 (diff)
build: Clean up build toolchain (and use musl for libc)
Using musl is required to match several functions that use <math.h> floating point functions like isnan. This also removes a dependency on devkitA64. We previously only needed it because Clang insisted on using GCC to link the final executable owing to the use of a "bare metal" target like aarch64-none-elf. We can make Clang invoke the linker itself by using a Linux target.
-rw-r--r--.gitignore3
-rw-r--r--.gitmodules3
-rw-r--r--Dockerfile37
-rw-r--r--README.md7
-rw-r--r--ToolchainNX64.cmake45
-rw-r--r--toolchain/ToolchainNX64.cmake42
m---------toolchain/musl0
7 files changed, 49 insertions, 88 deletions
diff --git a/.gitignore b/.gitignore
index 343c32e3..a6609dec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,4 +28,5 @@ perf.mData.old
.gdb_history
.DS_Store
-tools/aarch64-none-elf-objdump \ No newline at end of file
+tools/aarch64-none-elf-objdump
+toolchain/clang/
diff --git a/.gitmodules b/.gitmodules
index 08dc5599..67907369 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -13,3 +13,6 @@
[submodule "lib/EventFlow"]
path = lib/EventFlow
url = https://github.com/open-ead/EventFlow
+[submodule "toolchain/musl"]
+ path = toolchain/musl
+ url = https://github.com/open-ead/botw-lib-musl
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 038229a7..00000000
--- a/Dockerfile
+++ /dev/null
@@ -1,37 +0,0 @@
-FROM ubuntu:latest
-
-MAINTAINER Léo <leo@leolam.fr>
-
-# devkitpro/devkita64:latest
-
-ENV DEBIAN_FRONTEND=noninteractive
-
-RUN apt-get update && \
- apt-get install -y --no-install-recommends apt-utils && \
- apt-get install -y --no-install-recommends sudo ca-certificates pkg-config curl wget xz-utils make git gnupg && \
- apt-get install -y --no-install-recommends gdebi-core && \
- apt-get install -y --no-install-recommends cmake && \
- apt-get install -y --no-install-recommends libncurses5 ninja-build && \
- apt-get clean && \
- rm -rf /var/lib/apt/lists/*
-
-RUN wget https://github.com/devkitPro/pacman/releases/latest/download/devkitpro-pacman.amd64.deb && \
- gdebi -n devkitpro-pacman.amd64.deb && \
- rm devkitpro-pacman.amd64.deb && \
- dkp-pacman -Scc --noconfirm
-
-RUN dkp-pacman -Syyu --noconfirm switch-dev && \
- dkp-pacman -Scc --noconfirm
-
-ENV DEVKITPRO=/opt/devkitpro
-ENV DEVKITA64=/opt/devkitpro/devkitA64
-ENV PATH=${DEVKITPRO}/tools/bin:$DEVKITA64/bin:$PATH
-
-# BotW build
-
-RUN wget https://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz && \
- tar xf clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz && \
- rm clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz && \
- mv clang+llvm-4.0.1-x86_64-linux-gnu-debian8 /opt/clang-4.0.1
-
-ENV UKING_CLANG=/opt/clang-4.0.1
diff --git a/README.md b/README.md
index a624af9a..9a8179fa 100644
--- a/README.md
+++ b/README.md
@@ -135,17 +135,14 @@ First, set up the build environment by following the instructions below. Then fo
* For Ubuntu or Debian users, install it with `sudo apt install ninja-build`
* CMake 3.13+
* If you are on Ubuntu 18.04, you must [update CMake by using the official CMake APT repository](https://apt.kitware.com/).
-* devkitA64
- * [Follow this guide to set it up.](https://switchbrew.org/wiki/Setting_up_Development_Environment#Setup)
Using Linux (or WSL) is recommended but not required. The rest of this guide assumes that you are using a Linux environment, though.
### Building for Switch
1. After cloning this repository, run: `git submodule update --init --recursive`
-2. Run: `env UKING_CLANG=$1 DEVKITA64=$2 cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=../ToolchainNX64.cmake -B build`
- * Replace `$1` with the path to the extracted Clang archive, such that `$1/bin/clang` exists. This should be an absolute path; use `/home/<name>` instead of `~`.
- * Replace `$2` with the path to devkitA64. On Linux, this is typically `/opt/devkitpro/devkitA64`.
+2. Run: `env UKING_CLANG=$$$$$ cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=toolchain/ToolchainNX64.cmake -B build`
+ * Replace `$$$$$` with the path to the extracted Clang archive, such that `$1/bin/clang` exists. This should be an absolute path; use `/home/<name>` instead of `~`.
3. Start the build by running: `ninja -C build`
On subsequent builds, just run `ninja -C build` from the project root.
diff --git a/ToolchainNX64.cmake b/ToolchainNX64.cmake
deleted file mode 100644
index d9af3beb..00000000
--- a/ToolchainNX64.cmake
+++ /dev/null
@@ -1,45 +0,0 @@
-if (NOT DEFINED ENV{UKING_CLANG})
- message(FATAL_ERROR "Please define the UKING_CLANG env variable. It should point to a path such that $UKING_CLANG/bin/clang exists")
-endif()
-
-if (NOT DEFINED ENV{DEVKITA64})
- message(FATAL_ERROR "Please define the DEVKITA64 env variable.")
-endif()
-
-set(UKING_CLANG "$ENV{UKING_CLANG}")
-set(DEVKITA64 "$ENV{DEVKITA64}")
-set(NX64_OPT_FLAGS "-O3 -g")
-set(triple aarch64-none-elf)
-
-set(CMAKE_SYSTEM_NAME Generic)
-set(CMAKE_SYSTEM_VERSION 1)
-set(CMAKE_SYSTEM_PROCESSOR aarch64)
-
-set(CMAKE_SYSROOT ${UKING_CLANG})
-set(CMAKE_C_COMPILER "${UKING_CLANG}/bin/clang")
-set(CMAKE_C_COMPILER_TARGET ${triple})
-set(CMAKE_CXX_COMPILER "${UKING_CLANG}/bin/clang++")
-set(CMAKE_CXX_COMPILER_TARGET ${triple})
-
-set(CMAKE_C_FLAGS_RELEASE ${NX64_OPT_FLAGS})
-set(CMAKE_CXX_FLAGS_RELEASE ${NX64_OPT_FLAGS})
-set(CMAKE_C_FLAGS_RELWITHDEBINFO ${NX64_OPT_FLAGS})
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${NX64_OPT_FLAGS})
-
-set(ARCH "-mcpu=cortex-a57+fp+simd+crypto+crc")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH} -isystem ${DEVKITA64}/aarch64-none-elf/include")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${UKING_CLANG}/include/c++/v1 -D _LIBCPP_HAS_THREAD_API_PTHREAD ${CMAKE_C_FLAGS}")
-set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -x assembler-with-cpp ${ARCH}")
-
-add_compile_options(-fPIC -stdlib=libc++ -mno-implicit-float)
-add_link_options(-B ${DEVKITA64}/bin -fPIC -Wl,-Bsymbolic-functions -shared -nodefaultlibs)
-if(EXISTS "${DEVKITA64}/bin/ld.lld")
- add_link_options(-fuse-ld=lld -Wl,-z,notext)
-endif()
-add_definitions(-D SWITCH -D __DEVKITA64__ -D __ELF__)
-add_definitions(-D NNSDK)
-add_definitions(-D MATCHING_HACK_NX_CLANG)
-
-# Helps with matching as this causes Clang to emit debug type info even for dynamic classes
-# with undefined vtables.
-add_compile_options(-fstandalone-debug)
diff --git a/toolchain/ToolchainNX64.cmake b/toolchain/ToolchainNX64.cmake
new file mode 100644
index 00000000..bc967750
--- /dev/null
+++ b/toolchain/ToolchainNX64.cmake
@@ -0,0 +1,42 @@
+if (DEFINED ENV{UKING_CLANG})
+ set(UKING_CLANG "$ENV{UKING_CLANG}")
+else()
+ set(UKING_CLANG "toolchain/clang")
+endif()
+
+set(NX64_OPT_FLAGS "-O3 -g")
+set(NX64_TRIPLE aarch64-linux-elf)
+
+set(CMAKE_SYSTEM_NAME Generic)
+set(CMAKE_SYSTEM_VERSION 1)
+set(CMAKE_SYSTEM_PROCESSOR aarch64)
+
+set(CMAKE_SYSROOT ${CMAKE_CURRENT_LIST_DIR}/musl)
+set(CMAKE_C_COMPILER "${UKING_CLANG}/bin/clang")
+set(CMAKE_C_COMPILER_TARGET ${NX64_TRIPLE})
+set(CMAKE_CXX_COMPILER "${UKING_CLANG}/bin/clang++")
+set(CMAKE_CXX_COMPILER_TARGET ${NX64_TRIPLE})
+
+set(CMAKE_C_FLAGS_RELEASE ${NX64_OPT_FLAGS})
+set(CMAKE_CXX_FLAGS_RELEASE ${NX64_OPT_FLAGS})
+set(CMAKE_C_FLAGS_RELWITHDEBINFO ${NX64_OPT_FLAGS})
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${NX64_OPT_FLAGS})
+
+# Target options
+add_compile_options(-mcpu=cortex-a57+fp+simd+crypto+crc)
+add_compile_options(-mno-implicit-float)
+# Environment
+add_compile_options(-stdlib=libc++)
+add_compile_options(-fPIC)
+# Helps with matching as this causes Clang to emit debug type info even for dynamic classes
+# with undefined vtables.
+add_compile_options(-fstandalone-debug)
+
+add_definitions(-D SWITCH)
+add_definitions(-D NNSDK)
+add_definitions(-D MATCHING_HACK_NX_CLANG)
+
+add_link_options(-stdlib=libc++ -nostdlib)
+add_link_options(-fPIC -Wl,-Bsymbolic-functions -shared)
+# Use lld for performance reasons (and because we don't want a dependency on GNU tools)
+add_link_options(-fuse-ld=lld)
diff --git a/toolchain/musl b/toolchain/musl
new file mode 160000
+Subproject 9a9252a54a67f54c066966f8f0599c450391bd4