Talk:D on esp32/esp8266(llvm-xtensa+ldc) and how to get started

From D Wiki
Revision as of 14:09, 29 May 2023 by Jmeeuws (talk | contribs) (2023 update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

2023 update

Updated version that compiles without issues, even clang -c works. The main change is that espressif now uses a single repo that just a fork of llvm. Espressif is already at llvm 16, while ldc still uses 15 in master at this time, so I used espressif's latest llvm 15 fork.

Place this script as build-toolchain.sh in an empty directory and run it: (Note that you might have to temporarily uninstall llvm, clang and ldc from your system first)

#!/usr/bin/env bash

set -e

function gcl
{
    git clone --recurse-submodules --depth 1 $@
}

[[ -d llvm-source ]] && rm -rf llvm-source
[[ -d llvm-build ]] && rm -rf llvm-build
gcl --branch "esp-15.0.0-20230404" https://github.com/espressif/llvm-project.git llvm-source
cmake \
    -S llvm-source/llvm \
    -B llvm-build \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=Debug \
    -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa" \
    -DLLVM_ENABLE_PROJECTS="clang" \
    -DCMAKE_INSTALL_PREFIX=/opt/llvm-xtensa \
    -DCMAKE_C_COMPILER=gcc \
    -DCMAKE_CXX_COMPILER=g++ \
    -DCMAKE_ASM_COMPILER=gcc
cmake --build llvm-build
sudo cmake --install llvm-build

[[ -d ldc-source ]] && rm -rf ldc-source
[[ -d ldc-build ]] && rm -rf ldc-build
gcl --branch "v1.32.2" https://github.com/ldc-developers/ldc.git ldc-source
cmake \
    -S ldc-source \
    -B ldc-build \
    -G Ninja \
    -DCMAKE_BUILD_TYPE=Debug \
    -DCMAKE_INSTALL_PREFIX=/opt/ldc-xtensa \
    -DLLVM_ROOT_DIR=/opt/llvm-xtensa \
    -DCMAKE_C_COMPILER=gcc \
    -DCMAKE_CXX_COMPILER=g++ \
    -DCMAKE_ASM_COMPILER=gcc
cmake --build ldc-build
sudo cmake --install ldc-build

Note that I've yet to use Release mode.

I have yet to change the actual tutorial to include this.