-
Notifications
You must be signed in to change notification settings - Fork 22
Regain control over the SDK libraries [new variant using rebuilt newlib from Debian sources) #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iartemov-ledger
merged 8 commits into
master
from
feat/regain_control_over_libs_2_master
Sep 19, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d3edf4
New script to build clang rt builtins
apaillier-ledger 4ee870d
New workflow to trigger the build of clang rt builtins
apaillier-ledger 6e60d6e
Enables the use of clang rt builtins instead of libgcc
apaillier-ledger d9959b5
Automatic PR creation with clangrt
iartemov-ledger 1c0a33a
New script to build libc and libm
iartemov-ledger 066e690
Adding newlib build to the workflow
iartemov-ledger 744e9f2
Updating static SDK libraries
3954b8f
Generalizing the lib build workflow name
iartemov-ledger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| name: Build SDK libraries and make PR to update them | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| target_sdk_branch: | ||
| type: string | ||
| required: false | ||
| default: 'master' | ||
| create_pr: | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
|
|
||
| env: | ||
| GIT_USER_EMAIL: '[email protected]' | ||
| GIT_USER_NAME: 'SDKLibsUpdaterGithub' | ||
| UPDATE_BRANCH: 'sdk_libs_update' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: | ||
| - core: cortex-m3 | ||
| se: st33 | ||
| - core: cortex-m35p+nodsp | ||
| se: st33k1 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| sparse-checkout: | | ||
| tools/build_clangrt_builtins.sh | ||
| tools/build_newlib.sh | ||
| sparse-checkout-cone-mode: false | ||
|
|
||
| - run: ./tools/build_clangrt_builtins.sh -t ${{ matrix.target.core }} -o artifact/arch/${{ matrix.target.se }}/lib | ||
|
|
||
| - run: ./tools/build_newlib.sh -t ${{ matrix.target.core }} -o artifact/arch/${{ matrix.target.se }}/lib | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: arch-${{ matrix.target.se }} | ||
| path: artifact/ | ||
|
|
||
| merge: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/upload-artifact/merge@v4 | ||
| with: | ||
| name: arch | ||
| pattern: arch-* | ||
| delete-merged: true | ||
|
|
||
| pr_create: | ||
|
||
| needs: merge | ||
| runs-on: ubuntu-latest | ||
| if: ${{ success() && inputs.create_pr }} | ||
| continue-on-error: true | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Clone repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # by default the action uses fetch-depth = 1, which creates | ||
| # shallow repositories from which we can't push | ||
| fetch-depth: 0 | ||
| ref: ${{ inputs.target_sdk_branch }} | ||
|
|
||
| - name: Download Binaries artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: arch | ||
|
|
||
| - name: PR creation | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| TARGET_BRANCH: ${{ inputs.target_sdk_branch }} | ||
| run: | | ||
| git config --global user.email "$GIT_USER_EMAIL" | ||
| git config --global user.name "$GIT_USER_NAME" | ||
| git switch --create "$UPDATE_BRANCH" | ||
| git add -A . | ||
| git commit -m 'Updating static SDK libraries' | ||
| git push -u origin "$UPDATE_BRANCH" | ||
| gh pr create -B "$TARGET_BRANCH" --title '[SDK_LIBS_UPDATE] Updating static SDK libraries' --body 'Created by Github workflow "${{ github.workflow }}", job "${{ github.job }}", run "${{ github.run_id }}".' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e | ||
|
|
||
| TARGET_CPU="" | ||
| OUTPUT_DIR="" | ||
|
|
||
| while getopts "t:o:" opt | ||
| do | ||
| case "$opt" in | ||
| t) | ||
| TARGET_CPU="$OPTARG" | ||
| ;; | ||
| o) | ||
| OUTPUT_DIR="$OPTARG" | ||
| ;; | ||
| ?) | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| shift "$((OPTIND - 1))" | ||
|
|
||
| if [ -z "$TARGET_CPU" ] || [ -z "$OUTPUT_DIR" ] | ||
| then | ||
| echo "Usage: $0 -t TARGET_CPU -o OUTPUT_FILE" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "$OUTPUT_DIR" | ||
| OUTPUT_DIR=$(realpath "$OUTPUT_DIR") | ||
|
|
||
| # enable source repository | ||
| sed -i 's/^\(Types: deb\)$/\1 deb-src/g' /etc/apt/sources.list.d/debian.sources | ||
|
|
||
| apt update | ||
|
|
||
| apt install -y --no-install-recommends \ | ||
| dpkg-dev \ | ||
| llvm-dev | ||
|
|
||
| LLVM_VERSION=$(clang --version | head -n1 | rev | cut -d" " -f1 | rev) | ||
| LLVM_MAJOR_VERSION=$(echo "$LLVM_VERSION" | cut -d. -f1) | ||
|
|
||
| cd /tmp | ||
|
|
||
| LLVM_DIR="llvm-toolchain-$LLVM_MAJOR_VERSION-$LLVM_VERSION" | ||
| if [ ! -d "$LLVM_DIR" ] | ||
| then | ||
| # install Debian source package | ||
| apt source "llvm-toolchain-$LLVM_MAJOR_VERSION" | ||
| fi | ||
|
|
||
| cd "$LLVM_DIR" | ||
| rm -rf build | ||
| mkdir build | ||
| cd build | ||
|
|
||
| TARGET=arm-none-eabi | ||
| SYSROOT=/usr/lib/arm-none-eabi | ||
|
|
||
| cmake ../compiler-rt \ | ||
| -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \ | ||
| -DCOMPILER_RT_OS_DIR="baremetal" \ | ||
| -DCOMPILER_RT_BUILD_BUILTINS=ON \ | ||
| -DCOMPILER_RT_BUILD_CRT=OFF \ | ||
| -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ | ||
| -DCOMPILER_RT_BUILD_XRAY=OFF \ | ||
| -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ | ||
| -DCOMPILER_RT_BUILD_PROFILE=OFF \ | ||
| -DCOMPILER_RT_BUILD_MEMPROF=OFF \ | ||
| -DCOMPILER_RT_BUILD_ORC=OFF \ | ||
| -DCMAKE_C_COMPILER="$(which clang)" \ | ||
| -DCMAKE_C_COMPILER_TARGET="${TARGET}" \ | ||
| -DCMAKE_ASM_COMPILER_TARGET="${TARGET}" \ | ||
| -DCMAKE_AR="$(which llvm-ar)" \ | ||
| -DCMAKE_NM="$(which llvm-nm)" \ | ||
| -DCMAKE_RANLIB="$(which llvm-ranlib)" \ | ||
| -DCOMPILER_RT_BAREMETAL_BUILD=ON \ | ||
| -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \ | ||
| -DLLVM_CONFIG_PATH="$(which llvm-config)" \ | ||
| -DCOMPILER_RT_HAS_FPIC_FLAG=OFF \ | ||
| -DCMAKE_C_FLAGS="-mcpu=${TARGET_CPU} -mlittle-endian -mthumb -Oz -g0 -fropi -frwpi" \ | ||
| -DCMAKE_ASM_FLAGS="-mcpu=${TARGET_CPU} -mlittle-endian -mthumb" \ | ||
| -DCMAKE_SYSROOT="$SYSROOT" | ||
| make -j | ||
| mkdir -p "$OUTPUT_DIR" | ||
| cp lib/baremetal/libclang_rt.builtins-arm.a "$OUTPUT_DIR/libclang_rt.builtins.a" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -exu | ||
|
|
||
| TARGET_CPU="" | ||
| OUTPUT_DIR="" | ||
|
|
||
| while getopts "t:o:" opt | ||
| do | ||
| case "$opt" in | ||
| t) | ||
| TARGET_CPU="$OPTARG" | ||
| ;; | ||
| o) | ||
| OUTPUT_DIR="$OPTARG" | ||
| ;; | ||
| ?) | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| shift "$((OPTIND - 1))" | ||
|
|
||
| if [ -z "${TARGET_CPU}" ] || [ -z "${OUTPUT_DIR}" ] | ||
| then | ||
| echo "Usage: $0 -t TARGET_CPU -o OUTPUT_FILE" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "$OUTPUT_DIR" | ||
| OUTPUT_DIR=$(realpath "$OUTPUT_DIR") | ||
|
|
||
| # Working in a temporary folder | ||
| mkdir tmp && cd tmp | ||
|
|
||
| # Enabling source repository | ||
| sed -i 's/^\(Types: deb\)$/\1 deb-src/g' /etc/apt/sources.list.d/debian.sources | ||
|
|
||
| # Installing newlib build dependencies | ||
| apt update | ||
| apt install -y --no-install-recommends texinfo dpkg-dev | ||
|
|
||
| # Get the latest fixed version for this OS version | ||
| apt source newlib | ||
|
|
||
| # Entering the source directory | ||
| cd */ | ||
|
|
||
| # ENV SETUP | ||
| WORKDIR="$(pwd)" | ||
| #SRC="${WORKDIR}/newlib" | ||
| BUILD="${WORKDIR}/arm_none_eabi_build" | ||
| INSTALL="${WORKDIR}/arm_none_eabi_install" | ||
|
|
||
| # Build configuration | ||
| mkdir -p "${BUILD}" "${INSTALL}" | ||
| cd "${BUILD}" | ||
|
|
||
| CFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections -fshort-wchar -DPREFER_SIZE_OVER_SPEED -mcpu=${TARGET_CPU} -mthumb -mlittle-endian" \ | ||
0pendev marked this conversation as resolved.
Show resolved
Hide resolved
bboilot-ledger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ../configure \ | ||
| `# Setup` \ | ||
| --host=x86_64-linux-gnu `# Host` \ | ||
| --target=arm-none-eabi ` # Target` \ | ||
| --disable-multilib `# Building only one library` \ | ||
| --prefix="${INSTALL}" `# Installation prefix` \ | ||
| `# Options` \ | ||
| --disable-silent-rules `# verbose build output (undo: "make V=0")` \ | ||
| --disable-dependency-tracking `# speeds up one-time build` \ | ||
| --enable-newlib-reent-small `# enable small reentrant struct support` \ | ||
| --disable-newlib-fvwrite-in-streamio `# disable iov in streamio ` \ | ||
| --disable-newlib-fseek-optimization `# disable fseek optimization` \ | ||
| --disable-newlib-wide-orient `# Turn off wide orientation in streamio`\ | ||
| --enable-newlib-nano-malloc `# use small-footprint nano-malloc implementation`\ | ||
| --disable-newlib-unbuf-stream-opt `# disable unbuffered stream optimization in streamio` \ | ||
| --enable-lite-exit `# enable light weight exit` \ | ||
| --enable-newlib-global-atexit `# enable atexit data structure as global` \ | ||
| --enable-newlib-nano-formatted-io `# Use small-footprint nano-formatted-IO implementation`\ | ||
| --disable-newlib-supplied-syscalls `# disable newlib from supplying syscalls`\ | ||
| --disable-nls `# do not use Native Language Support` \ | ||
| --enable-target-optspace `# optimize for space (emits -g -Os)` | ||
|
|
||
|
|
||
| # Compilation | ||
| make "-j$(nproc)" | ||
| make install | ||
|
|
||
| # Removing the .ARM.exidx section | ||
| arm-none-eabi-objcopy -R .ARM.exidx "${INSTALL}/arm-none-eabi/lib/libc.a" | ||
|
|
||
| # Stripping debug symbols | ||
| arm-none-eabi-strip --strip-debug "${INSTALL}/arm-none-eabi/lib/libc.a" | ||
| arm-none-eabi-strip --strip-debug "${INSTALL}/arm-none-eabi/lib/libm.a" | ||
|
|
||
| # Copy back | ||
| cp "${INSTALL}/arm-none-eabi/lib/libc.a" "$OUTPUT_DIR" | ||
| cp "${INSTALL}/arm-none-eabi/lib/libm.a" "$OUTPUT_DIR" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.