Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 104 additions & 1 deletion compiler-rt.be0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env beesh

# BEE_VERSION compiler-rt-23.1.3-0
# BEE_VERSION compiler-rt-23.1.3-1

#SRCURL[0]="https://github.com/llvm/llvm-project/releases/download/llvmorg-${PKGVERSION}/llvm-project-${PKGVERSION}.src.tar.xz"
SRCURL[0]="https://beehive.molgen.mpg.de/d7e227fe471d80d5e2d411127a0123b1/llvm-project-23.1.3.src.tar.xz"
Expand All @@ -11,6 +11,19 @@ SRCURL[0]="https://beehive.molgen.mpg.de/d7e227fe471d80d5e2d411127a0123b1/llvm-p

sourcesubdir_append compiler-rt

# Bare-metal Arm builtins, one build per multilib variant: the directory below
# ${LIBDIR}/clang-runtimes, the target, and the flags. multilib.yaml, written
# in mee_install(), lets clang pick a variant from -mcpu/-mfloat-abi/-mfpu.
# picolibc.be0 installs the C library into the same directories.
BAREMETAL_VARIANTS=(
"arm-none-eabi/armv6m_soft_nofp thumbv6m-none-eabi -mfloat-abi=soft"
"arm-none-eabi/armv7m_soft_nofp thumbv7m-none-eabi -mfloat-abi=soft"
"arm-none-eabi/armv7em_soft_fpv4_sp_d16 thumbv7em-none-eabi -mfloat-abi=softfp -mfpu=fpv4-sp-d16"
"arm-none-eabi/armv7em_hard_fpv4_sp_d16 thumbv7em-none-eabihf -mfloat-abi=hard -mfpu=fpv4-sp-d16"
"arm-none-eabi/armv8m.main_soft_fp thumbv8m.main-none-eabi -mfloat-abi=softfp -mfpu=fpv5-sp-d16"
"arm-none-eabi/armv8m.main_hard_fp thumbv8m.main-none-eabihf -mfloat-abi=hard -mfpu=fpv5-sp-d16"
)

#mee_extract() {
# bee_extract "${@}"
#}
Expand All @@ -33,12 +46,102 @@ mee_configure() {
-DCMAKE_CXX_COMPILER=clang++ \
-Wno-dev \
-G Ninja

local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"
start_cmd cmake \
-S ${S}/lib/builtins \
-B ${B}/baremetal/${dir} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Generic \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_ASM_COMPILER=clang \
-DCMAKE_C_COMPILER_TARGET=${target} \
-DCMAKE_ASM_COMPILER_TARGET=${target} \
-DCMAKE_C_FLAGS="${flags}" \
-DCMAKE_ASM_FLAGS="${flags}" \
-DCMAKE_AR=$(command -v llvm-ar) \
-DCMAKE_RANLIB=$(command -v llvm-ranlib) \
-DCOMPILER_RT_STANDALONE_BUILD=ON \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON \
-DCOMPILER_RT_INSTALL_LIBRARY_DIR=${LIBDIR}/clang-runtimes/${dir}/lib \
-DLLVM_CMAKE_DIR=$(llvm-config --cmakedir) \
-Wno-dev \
-G Ninja
done
}

mee_build() {
start_cmd ninja -v -C ${B} ${BEE_NINJAFLAGS} "${@}"

local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"
start_cmd ninja -v -C ${B}/baremetal/${dir} ${BEE_NINJAFLAGS} "${@}"
done
}

mee_install() {
DESTDIR=${D} start_cmd ninja -C ${B} install "${@}"

local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"
DESTDIR=${D} start_cmd ninja -C ${B}/baremetal/${dir} install "${@}"

# compiler-rt appends the normalized target to the library
# directory, but clang only searches the variant's lib directory.
local libdir=${D}${LIBDIR}/clang-runtimes/${dir}/lib
start_cmd mv ${libdir}/*/libclang_rt.builtins.a ${libdir}/
start_cmd rmdir ${libdir}/*/
done

# A variant matches if clang's flags (see -print-multi-flags-experimental)
# contain all of its flags, and of the matching variants the last one
# wins. The mappings let compatible cores use them: a library runs on any
# core of the same or a later architecture, and an FPv5 unit executes
# FPv4 code. The variants without FPU require -mfpu=none, as their crt0
# does not enable the FPU, which code built with -mfloat-abi=softfp for
# a core with FPU uses.
cat > ${D}${LIBDIR}/clang-runtimes/multilib.yaml <<-'EOF'
MultilibVersion: 1.0

Groups:
- Name: stdlibs
Type: Exclusive

Variants:
- Dir: arm-none-eabi/armv6m_soft_nofp
Flags: [--target=thumbv6m-unknown-none-eabi, -mfpu=none]
Group: stdlibs
- Dir: arm-none-eabi/armv7m_soft_nofp
Flags: [--target=thumbv7m-unknown-none-eabi, -mfpu=none]
Group: stdlibs
- Dir: arm-none-eabi/armv7em_soft_fpv4_sp_d16
Flags: [--target=thumbv7em-unknown-none-eabi, -mfpu=fpv4-sp-d16]
Group: stdlibs
- Dir: arm-none-eabi/armv7em_hard_fpv4_sp_d16
Flags: [--target=thumbv7em-unknown-none-eabihf, -mfpu=fpv4-sp-d16]
Group: stdlibs
- Dir: arm-none-eabi/armv8m.main_soft_fp
Flags: [--target=thumbv8m.main-unknown-none-eabi, -mfpu=fpv5-sp-d16]
Group: stdlibs
- Dir: arm-none-eabi/armv8m.main_hard_fp
Flags: [--target=thumbv8m.main-unknown-none-eabihf, -mfpu=fpv5-sp-d16]
Group: stdlibs

Mappings:
- Match: --target=thumbv8m\.base-unknown-none-eabi
Flags: [--target=thumbv6m-unknown-none-eabi]
- Match: --target=thumbv(7em|8m\.main|8\.1m\.main)-unknown-none-eabi
Flags: [--target=thumbv7m-unknown-none-eabi]
- Match: -mfpu=fpv5-(sp-)?d16
Flags: [-mfpu=fpv4-sp-d16]
- Match: -mfpu=fpv5-d16
Flags: [-mfpu=fpv5-sp-d16]
EOF
}
91 changes: 91 additions & 0 deletions picolibc.be0
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env beesh

# BEE_VERSION picolibc-1.8.12-0

# SRCURL[0]="https://github.com/picolibc/picolibc/releases/download/${PKGVERSION}/picolibc-${PKGVERSION}.tar.xz"
SRCURL[0]="https://beehive.molgen.mpg.de/7219ddf0193c83528f22b7b8fbc1fff4/picolibc-1.8.12.tar.xz"

# PATCHURL+=()

# build_in_sourcedir

# sourcesubdir_append src

# Bare-metal Arm C library, one build per multilib variant: the directory
# below ${LIBDIR}/clang-runtimes, the target, and the flags. Keep the list in
# sync with compiler-rt.be0, which builds the builtins for these variants and
# installs the multilib.yaml that lets clang pick one.
BAREMETAL_VARIANTS=(
"arm-none-eabi/armv6m_soft_nofp thumbv6m-none-eabi -mfloat-abi=soft"
"arm-none-eabi/armv7m_soft_nofp thumbv7m-none-eabi -mfloat-abi=soft"
"arm-none-eabi/armv7em_soft_fpv4_sp_d16 thumbv7em-none-eabi -mfloat-abi=softfp -mfpu=fpv4-sp-d16"
"arm-none-eabi/armv7em_hard_fpv4_sp_d16 thumbv7em-none-eabihf -mfloat-abi=hard -mfpu=fpv4-sp-d16"
"arm-none-eabi/armv8m.main_soft_fp thumbv8m.main-none-eabi -mfloat-abi=softfp -mfpu=fpv5-sp-d16"
"arm-none-eabi/armv8m.main_hard_fp thumbv8m.main-none-eabihf -mfloat-abi=hard -mfpu=fpv5-sp-d16"
)

#mee_extract() {
# bee_extract "${@}"
#}

#mee_patch() {
# bee_patch "${@}"
#}

mee_configure() {
local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"

# -nostdlibinc keeps the headers of an installed picolibc out of
# the build, -nostdlib the libraries. clang's bare-metal driver
# defaults to GNU ld, which on MarIuX only knows x86.
mkdir -p ${B}/cross/${dir%/*}
cat > ${B}/cross/${dir}.txt <<-EOF
[binaries]
c = ['clang', '--target=${target}', $(printf "'%s', " ${flags})'-nostdlibinc', '-nostdlib']
c_ld = 'lld'
ar = 'llvm-ar'
nm = 'llvm-nm'
strip = 'llvm-strip'

[host_machine]
system = 'none'
cpu_family = 'arm'
cpu = 'arm'
endian = 'little'

[properties]
skip_sanity_check = true
EOF

# Without -Dspecsdir=none the GCC specs file would be installed
# into clang's install directory, /usr/bin.
start_cmd meson setup \
--cross-file ${B}/cross/${dir}.txt \
--prefix=${LIBDIR}/clang-runtimes/${dir} \
--includedir=include \
--libdir=lib \
--wrap-mode=nofallback \
-Dmultilib=false \
-Dspecsdir=none \
${B}/${dir} \
${S}
done
}

mee_build() {
local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"
start_cmd ninja -v -C ${B}/${dir} ${BEE_NINJAFLAGS} "${@}"
done
}

mee_install() {
local dir target flags
for variant in "${BAREMETAL_VARIANTS[@]}" ; do
read -r dir target flags <<< "${variant}"
DESTDIR=${D} start_cmd ninja -C ${B}/${dir} install "${@}"
done
}
Loading