mirror of https://github.com/zeldaret/botw.git
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.
This commit is contained in:
parent
1c8152de22
commit
8cf3dd776b
|
@ -28,4 +28,5 @@ perf.mData.old
|
||||||
.gdb_history
|
.gdb_history
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
tools/aarch64-none-elf-objdump
|
tools/aarch64-none-elf-objdump
|
||||||
|
toolchain/clang/
|
||||||
|
|
|
@ -13,3 +13,6 @@
|
||||||
[submodule "lib/EventFlow"]
|
[submodule "lib/EventFlow"]
|
||||||
path = lib/EventFlow
|
path = lib/EventFlow
|
||||||
url = https://github.com/open-ead/EventFlow
|
url = https://github.com/open-ead/EventFlow
|
||||||
|
[submodule "toolchain/musl"]
|
||||||
|
path = toolchain/musl
|
||||||
|
url = https://github.com/open-ead/botw-lib-musl
|
||||||
|
|
37
Dockerfile
37
Dockerfile
|
@ -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
|
|
|
@ -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`
|
* For Ubuntu or Debian users, install it with `sudo apt install ninja-build`
|
||||||
* CMake 3.13+
|
* 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/).
|
* 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.
|
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
|
### Building for Switch
|
||||||
|
|
||||||
1. After cloning this repository, run: `git submodule update --init --recursive`
|
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`
|
2. Run: `env UKING_CLANG=$$$$$ cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=toolchain/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 `$$$$$` 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`.
|
|
||||||
3. Start the build by running: `ninja -C build`
|
3. Start the build by running: `ninja -C build`
|
||||||
|
|
||||||
On subsequent builds, just run `ninja -C build` from the project root.
|
On subsequent builds, just run `ninja -C build` from the project root.
|
||||||
|
|
|
@ -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)
|
|
|
@ -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)
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 9a9252a54a67f54c066966f8f0599c450391bd44
|
Loading…
Reference in New Issue