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
12 changes: 3 additions & 9 deletions .github/scripts/build_all_variants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set -x

# Default values
DIR="."
VERSION="latest"
COMPILER_PROFILE="hal/tc/llvm"
ARCH_LIST=("cortex-m3")
CONAN_VERSION=2.23.0
Expand All @@ -28,10 +27,6 @@ while [[ $# -gt 0 ]]; do
DIR="$2"
shift 2
;;
--version)
VERSION="$2"
shift 2
;;
--compiler-profile)
COMPILER_PROFILE="$2"
shift 2
Expand Down Expand Up @@ -61,7 +56,6 @@ echo "========================================"
echo "Baremetal Package Build Configuration"
echo "========================================"
echo "DIR: $DIR"
echo "VERSION: $VERSION"
echo "COMPILER_PROFILE: $COMPILER_PROFILE"
echo "CONAN_VERSION: $CONAN_VERSION"
echo "ARCH_LIST: ${ARCH_LIST[*]}"
Expand All @@ -77,9 +71,9 @@ conan hal setup
for ARCH in "${ARCH_LIST[@]}"; do
echo "Building for architecture: $ARCH"

conan build $DIR -s:h build_type=Debug -s:h os=baremetal -s:h arch=$ARCH --version $VERSION -pr:h $COMPILER_PROFILE --build=missing $EXTRA_CONAN_ARGS
conan build $DIR -pr:b default -s:h build_type=Debug -s:h os=baremetal -s:h arch=$ARCH -pr:h $COMPILER_PROFILE --build=missing --build-require $EXTRA_CONAN_ARGS

conan build $DIR -s:h build_type=MinSizeRel -s:h os=baremetal -s:h arch=$ARCH --version $VERSION -pr:h $COMPILER_PROFILE --build=missing $EXTRA_CONAN_ARGS
conan build $DIR -pr:b default -s:h build_type=MinSizeRel -s:h os=baremetal -s:h arch=$ARCH -pr:h $COMPILER_PROFILE --build=missing --build-require $EXTRA_CONAN_ARGS

conan build $DIR -s:h build_type=Release -s:h os=baremetal -s:h arch=$ARCH --version $VERSION -pr:h $COMPILER_PROFILE --build=missing $EXTRA_CONAN_ARGS
conan build $DIR -pr:b default -s:h build_type=Release -s:h os=baremetal -s:h arch=$ARCH -pr:h $COMPILER_PROFILE --build=missing --build-require $EXTRA_CONAN_ARGS
done
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ jobs:
ci_11_3:
uses: ./.github/workflows/11.3.yml
secrets: inherit
ci_11:
uses: ./.github/workflows/11.yml
secrets: inherit
ci_12_2:
uses: ./.github/workflows/12.2.yml
secrets: inherit
ci_12_3:
uses: ./.github/workflows/12.3.yml
secrets: inherit
ci_12:
uses: ./.github/workflows/12.yml
secrets: inherit
ci_13_2:
uses: ./.github/workflows/13.2.yml
secrets: inherit
ci_13_3:
uses: ./.github/workflows/13.3.yml
secrets: inherit
ci_13:
uses: ./.github/workflows/13.yml
secrets: inherit
ci_14_2:
uses: ./.github/workflows/14.2.yml
secrets: inherit
ci_14_3:
uses: ./.github/workflows/14.3.yml
secrets: inherit
ci_14:
uses: ./.github/workflows/14.yml
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
run: conan remote login -p $PASSWORD libhal $JFROG_USER

- name: 🆙 Upload package to Conan Package Repo
run: conan upload "arm-gnu-toolchain/*" --only-recipe --confirm -r=libhal
run: conan upload "arm-gnu-toolchain/${{ inputs.version }}" --only-recipe --confirm -r=libhal
3 changes: 1 addition & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ jobs:
run: conan hal setup

- name: 📦 Create Conan Package
working-directory: all
run: conan create . --version=${{ inputs.version }}
run: conan create all --version=${{ inputs.version }} -pr:b default -s:h build_type=MinSizeRel -s:h os=baremetal -s:h arch=cortex-m4 -pr:h conan/profiles/v1/arm-gcc-${{ inputs.version }}-no-tool --build=missing --build-require

- name: 📦 Build Demos Conan Package [ build_type=Debug ]
run: conan build demo -pr conan/profiles/v1/arm-gcc-${{ inputs.version }} --build=missing:cmake/* -s build_type=MinSizeRel -s:h os=baremetal -s:h arch=${{ inputs.arch }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/verify_and_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ jobs:
run: conan hal setup

- name: 📦 Create Conan Package
run: conan create all --version=${{ inputs.version }}
run: conan create all --version=${{ inputs.version }} -pr:b default -s:h build_type=Debug -s:h os=baremetal -s:h arch=cortex-m4 -pr:h conan/profiles/v1/arm-gcc-${{ inputs.version }}-no-tool --build=missing --build-require

- name: 📦 Build packages for all Cortex-M architectures
run: |
bash .github/scripts/build_all_variants.sh \
--dir demo \
--version ${{ inputs.version }} \
--compiler-profile conan/profiles/v1/arm-gcc-${{ inputs.version }} \
--conan-version 2.22.2 \
--arch-list cortex-m0,cortex-m0plus,cortex-m1,cortex-m3,cortex-m4,cortex-m4f,cortex-m7f,cortex-m7d,cortex-m23,cortex-m33,cortex-m33f,cortex-m35pf,cortex-m55,cortex-m85
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,30 @@ shasum -a 256 <insert file name>
```

Install this or the equivalent for your machine.

## Testing the Package

Build and test the package locally for both host and ARM Cortex-M targets:

```bash
# Test ARM Cortex-M cross-compilation
conan create all -pr:b default -pr:h cortex-m4f -pr:h llvm-X --version X --build-require
```

This downloads the binaries, verifies checksums, and creates the package.

## Build and Run the Demo

Install the toolchain profiles and build the demo application:

```bash
# Install toolchain profiles
conan config install -tf profiles/ -sf conan/profiles/v1/ .

# Build the demo for ARM Cortex-M (cross-compilation)
conan build demo -pr llvm-X -pr cortex-m4f --build=missing
```

> [!NOTE]
> Replace `linux_x86_64` and `cortex-m4f` with your platform's profile.
> Available profiles are in the `conan/profiles/v1/` directory.
81 changes: 53 additions & 28 deletions all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pathlib import Path
from conan import ConanFile
from conan.tools.files import get, copy, download
from conan.tools.files import get, copy
from conan.errors import ConanInvalidConfiguration
import os


required_conan_version = ">=2.0.0"
Expand Down Expand Up @@ -98,6 +97,7 @@ def package(self):
if self.options.local_path:
self.package_local_path()
return

# Download the toolchain...
OS = str(self._settings_build.os)
VERSION = self.version
Expand Down Expand Up @@ -145,8 +145,33 @@ def package_info(self):
"cpp": "arm-none-eabi-g++",
"asm": "arm-none-eabi-gcc",
})
f = os.path.join(self.package_folder, "res/toolchain.cmake")
self.conf_info.append("tools.cmake.cmaketoolchain:user_toolchain", f)

# Blank out CMakeToolchain's default optimization flags
# We manage all flags ourselves via tools.build:cxxflags
self.conf_info.define("tools.cmake.cmaketoolchain:extra_variables", {
# Blank out CMake's default optimization flags
"CMAKE_CXX_FLAGS_DEBUG": "",
"CMAKE_CXX_FLAGS_RELEASE": "",
"CMAKE_CXX_FLAGS_MINSIZEREL": "",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "",
"CMAKE_C_FLAGS_DEBUG": "",
"CMAKE_C_FLAGS_RELEASE": "",
"CMAKE_C_FLAGS_MINSIZEREL": "",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "",

# Cross-compilation workarounds
"CMAKE_CXX_COMPILER_WORKS": "TRUE",
"CMAKE_C_COMPILER_WORKS": "TRUE",
"CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY",

# Binutils
"CMAKE_AR": "arm-none-eabi-ar",
"CMAKE_RANLIB": "arm-none-eabi-ranlib",
})

TOOLCHAIN_PATH = str(Path(self.package_folder) / "res/toolchain.cmake")
self.conf_info.append(
"tools.cmake.cmaketoolchain:user_toolchain", TOOLCHAIN_PATH)

self.setup_bin_dirs()
self.inject_c_cxx_and_link_flags()
Expand All @@ -156,30 +181,30 @@ def inject_c_cxx_and_link_flags(self):
cxx_flags = []
exelinkflags = []

# Set optimization level based on build type
BUILD_TYPE = str(self.settings.build_type)
if BUILD_TYPE == "Debug":
# Use -Og for debuggable but LTO-compatible code
c_flags.append("-Og")
cxx_flags.append("-Og")

# Note about Og and O0. If you use LTO with O0, LTO seems to lose
# track of the symbols and gives an error stating that some symbols
# cannot be found like std::pmr::memory_resource or atomic
# operations. There seems to be some sort of issue of disabling
# optimizations but also enabling link time optimizations. To get
# over this, we've chosen to use `-Og` as your Debug build. This
# also provides the added benefit of apply reasonable
# optimizations, reducing binary size and improving performance
# without reducing debuggability.
elif BUILD_TYPE == "MinSizeRel":
# -Os prioritizes size optimizations
c_flags.append("-Os")
cxx_flags.append("-Os")
elif BUILD_TYPE in ["Release", "RelWithDebInfo"]:
# Use -O3 for maximum performance at the expense of space
c_flags.append("-O3")
cxx_flags.append("-O3")
if self.settings_target:
# Set optimization level based on build type
BUILD_TYPE = str(self.settings_target.build_type)
if BUILD_TYPE == "Debug":
# Use -Og for debuggable but LTO-compatible code
c_flags.append("-Og")
cxx_flags.append("-Og")
# Note about Og and O0. If you use LTO with O0, LTO seems to
# lose track of the symbols and gives an error stating that some
# symbols cannot be found like std::pmr::memory_resource or
# atomic operations. There seems to be some sort of issue of
# disabling optimizations but also enabling link time
# optimizations. To get over this, we've chosen to use `-Og` as
# your Debug build. This also provides the added benefit of
# apply reasonable optimizations, reducing binary size and
# improving performance without reducing debuggability.
elif BUILD_TYPE == "MinSizeRel":
# -Os prioritizes size optimizations
c_flags.append("-Os")
cxx_flags.append("-Os")
elif BUILD_TYPE in ["Release", "RelWithDebInfo"]:
# Use -O3 for maximum performance at the expense of space
c_flags.append("-O3")
cxx_flags.append("-O3")

if self.options.lto:
c_flags.append("-flto")
Expand Down
3 changes: 3 additions & 0 deletions all/test_package/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CompileFlags:
CompilationDatabase: .
BuiltinHeaders: QueryDriver
7 changes: 7 additions & 0 deletions all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(test_package LANGUAGES CXX)

add_executable(test_package main.cpp)
36 changes: 36 additions & 0 deletions all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import cross_building


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv"

def build_requirements(self):
self.tool_requires("cmake/[^4.0.0]")
self.tool_requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
# For cross-compilation toolchains, we just verify the binary was
# created.
# We cannot run ARM binaries on x86/ARM macOS/Linux/Windows hosts
if cross_building(self):
self.output.info(
"Cross-compilation successful! Binary created for target architecture.")
BINARY_PATH = Path(self.cpp.build.bindirs[0]) / "test_package"
if not BINARY_PATH.exists():
raise Exception(f"Expected binary not found at: {BINARY_PATH}")
self.output.success(f"Test binary exists at: {BINARY_PATH}")
else:
APP = Path(self.cpp.build.bindirs[0]) / "test_package"
self.run(APP, env="conanrun")
21 changes: 21 additions & 0 deletions all/test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cstdio>

int
main()
{
int a = 5;
int b = 12;
int c = a + b;

std::puts("Hello, world!");
std::printf("a = %d, b = %d\n", a, b);
std::printf("a + b = c = %d\n", c);

return 0;
}

// Use arm embedded to build stm32f103c8
//
// VERBOSE=1 conan test -pr stm32f103c8 -pr
// conan/profiles/v1/arm-gcc-14-no-tool test_package arm-gnu-toolchain/14
//
32 changes: 1 addition & 31 deletions all/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
# Append current directory to CMAKE_MODULE_PATH for making device specific
# cmake modules visible
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

# Skip Working compiler test which tends to fail in CMake due to it using build
# target architecture flags and not host architecture flags.
set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_C_COMPILER_WORKS TRUE)

# Need to force system to Generic & ARM as leaving this to Conan will result in
# pollution from host profile settings
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

# Target definition
# Custom utilities for libhal build system
set(TOOLCHAIN arm-none-eabi)

# Perform compiler test with static library
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# Set toolchain compilers
set(CMAKE_C_COMPILER ${TOOLCHAIN}-gcc${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}-g++${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN}-gcc${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_AR ${TOOLCHAIN}-ar${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_SIZE_UTIL ${TOOLCHAIN}-size${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_OBJDUMP ${TOOLCHAIN}-objdump${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_OBJCOPY ${TOOLCHAIN}-objcopy${CMAKE_EXECUTABLE_SUFFIX})
SET(CMAKE_RANLIB ${TOOLCHAIN}-ranlib${CMAKE_EXECUTABLE_SUFFIX})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_BINARY_DIR})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-11-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-11.3-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14.2
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-12-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-12.2-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14.2
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-12.3-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14.3
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-13-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14
5 changes: 5 additions & 0 deletions conan/profiles/v1/arm-gcc-13.2-no-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
compiler=gcc
compiler.cppstd=23
compiler.libcxx=libstdc++11
compiler.version=14.2
Loading