|
| 1 | +# Multiarch GNU Toolchain Conan Package |
| 2 | + |
| 3 | +A Conan tool package for the GNU GCC Toolchain, providing both native compilation |
| 4 | +(`gcc`, `g++`) and ARM cross-compilation (`arm-none-eabi-gcc`). By adding this |
| 5 | +tool package to your Conan build profile, your project can leverage GCC for |
| 6 | +development across multiple platforms and architectures. |
| 7 | + |
| 8 | +## ✨ Key Features |
| 9 | + |
| 10 | +- **Unified toolchain**: Single package provides both native GCC and ARM |
| 11 | + cross-compiler |
| 12 | +- **Automatic selection**: Correct toolchain variant chosen based on target |
| 13 | + OS/architecture |
| 14 | +- **Embedded ARM support**: Built-in support for ARM Cortex-M microcontrollers |
| 15 | +- **Native compilation**: Full GCC support for Linux and Windows |
| 16 | +- **Optimized binaries**: Native GCC from xpack-dev-tools, ARM cross-compiler |
| 17 | + from official ARM releases |
| 18 | + |
| 19 | +## 📋 Supported Versions & Platforms |
| 20 | + |
| 21 | +All binaries are downloaded from official sources: |
| 22 | + |
| 23 | +- Native GCC from [xpack-dev-tools](https://github.com/xpack-dev-tools/gcc-xpack/releases) |
| 24 | +- ARM cross-compiler from [ARM GNU Toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) |
| 25 | + |
| 26 | +### GCC 14 |
| 27 | + |
| 28 | +#### Native Compilation (Host Platforms) |
| 29 | + |
| 30 | +| Platform | x86_64 | ARM64 | |
| 31 | +|----------|--------|-------| |
| 32 | +| Linux | ✅ | ✅ | |
| 33 | +| Windows | ✅ | ❌ | |
| 34 | + |
| 35 | +> [!NOTE] |
| 36 | +> Native compilation (building executables for your host OS) is only supported |
| 37 | +> on Linux and Windows. macOS is not supported for native compilation. |
| 38 | +
|
| 39 | +#### ARM Cross-Compilation (Build Platforms) |
| 40 | + |
| 41 | +The following platforms can cross-compile for ARM Cortex-M targets: |
| 42 | + |
| 43 | +| Platform | x86_64 | ARM64 | |
| 44 | +|----------|--------|-------| |
| 45 | +| Linux | ✅ | ✅ | |
| 46 | +| macOS | ✅ | ✅ | |
| 47 | +| Windows | ✅ | ❌ | |
| 48 | + |
| 49 | +## 🚀 Quick Start |
| 50 | + |
| 51 | +To use the Multiarch GNU Toolchain for your application, install the pre-made |
| 52 | +compiler profiles to your local `conan2` cache: |
| 53 | + |
| 54 | +```bash |
| 55 | +conan config install -sf conan/profiles/v1 -tf profiles https://github.com/libhal/multiarch-gnu-toolchain.git |
| 56 | +``` |
| 57 | + |
| 58 | +This provides profiles accessible via `-pr gcc-14`. These profiles only include |
| 59 | +compiler information. You'll need a "target" profile to actually build something. |
| 60 | + |
| 61 | +### Native Development |
| 62 | + |
| 63 | +For native development on your host platform, the `gcc-14` profile automatically |
| 64 | +detects your OS and architecture: |
| 65 | + |
| 66 | +```bash |
| 67 | +# Build for your current platform (auto-detected) |
| 68 | +conan build demos/cpp -pr:a gcc-14 |
| 69 | +``` |
| 70 | + |
| 71 | +### ARM Cortex-M Cross-Compilation |
| 72 | + |
| 73 | +For embedded ARM Cortex-M development: |
| 74 | + |
| 75 | +```bash |
| 76 | +# Cortex-M4 with hardware floating point |
| 77 | +conan build demos/cpp -pr:a gcc-14 -pr cortex-m4f |
| 78 | + |
| 79 | +# Cortex-M7 with double-precision FPU |
| 80 | +conan build demos/cpp -pr:a gcc-14 -pr cortex-m7d |
| 81 | + |
| 82 | +# Cortex-M33 with hardware floating point |
| 83 | +conan build demos/cpp -pr:a gcc-14 -pr cortex-m33f |
| 84 | +``` |
| 85 | + |
| 86 | +## 🔗 Adding as a Dependency |
| 87 | + |
| 88 | +For this tool package to work correctly, the toolchain **MUST** be added as a |
| 89 | +dependency using `tool_requires` in at least one profile. |
| 90 | + |
| 91 | +```jinja2 |
| 92 | +[settings] |
| 93 | +compiler=gcc |
| 94 | +compiler.cppstd=23 |
| 95 | +compiler.libcxx=libstdc++11 |
| 96 | +compiler.version=14 |
| 97 | +
|
| 98 | +[tool_requires] |
| 99 | +multiarch-gnu-toolchain/14 |
| 100 | +``` |
| 101 | + |
| 102 | +By adding `multiarch-gnu-toolchain/14` to your profile, every dependency will |
| 103 | +use this toolchain for compilation. The tool package should NOT be directly |
| 104 | +added to an application's `conanfile.py`. |
| 105 | + |
| 106 | +### ARM Cortex-M Examples |
| 107 | + |
| 108 | +For ARM Cortex-M4 with hardware floating point: |
| 109 | + |
| 110 | +```plaintext |
| 111 | +[settings] |
| 112 | +arch=cortex-m4f |
| 113 | +build_type=Release |
| 114 | +os=baremetal |
| 115 | +``` |
| 116 | + |
| 117 | +For ARM Cortex-M7 with double-precision FPU: |
| 118 | + |
| 119 | +```plaintext |
| 120 | +[settings] |
| 121 | +arch=cortex-m7d |
| 122 | +build_type=Release |
| 123 | +os=baremetal |
| 124 | +``` |
| 125 | + |
| 126 | +## 🧾 Using Pre-made Profiles |
| 127 | + |
| 128 | +Install profiles into your local Conan cache: |
| 129 | + |
| 130 | +```bash |
| 131 | +conan config install -sf conan/profiles/v1 -tf profiles https://github.com/libhal/multiarch-gnu-toolchain.git |
| 132 | +``` |
| 133 | + |
| 134 | +Or from a locally cloned repo: |
| 135 | + |
| 136 | +```bash |
| 137 | +conan config install -sf conan/profiles/v1 -tf profiles . |
| 138 | +``` |
| 139 | + |
| 140 | +All profiles use `libstdc++11` as this is the latest GCC C++ ABI. |
| 141 | + |
| 142 | +## 📦 Building & Installing the Tool Package |
| 143 | + |
| 144 | +When you create the package, it downloads the appropriate compiler variant from |
| 145 | +official releases based on your build and target settings, then stores it in |
| 146 | +your local Conan package cache: |
| 147 | + |
| 148 | +```bash |
| 149 | +# For host platform development (native build) |
| 150 | +conan create all --version=14 --build-require |
| 151 | + |
| 152 | +# For ARM Cortex-M cross-compilation |
| 153 | +conan create all --version=14 --build-require -pr:h gcc-14 -pr cortex-m4f |
| 154 | +``` |
| 155 | + |
| 156 | +## 🎛️ Options |
| 157 | + |
| 158 | +Example profile options: |
| 159 | + |
| 160 | +```plaintext |
| 161 | +[options] |
| 162 | +multiarch-gnu-toolchain/*:default_arch=True |
| 163 | +multiarch-gnu-toolchain/*:lto=True |
| 164 | +multiarch-gnu-toolchain/*:fat_lto=True |
| 165 | +multiarch-gnu-toolchain/*:function_sections=True |
| 166 | +multiarch-gnu-toolchain/*:data_sections=True |
| 167 | +multiarch-gnu-toolchain/*:gc_sections=True |
| 168 | +multiarch-gnu-toolchain/*:default_libc=True |
| 169 | +``` |
| 170 | + |
| 171 | +### `local_path` (Default: `""`) |
| 172 | + |
| 173 | +Path to a local GCC toolchain directory. If not empty, the recipe will use this |
| 174 | +path instead of downloading the official toolchain. Useful for custom-built |
| 175 | +toolchains or alternative binary sources. |
| 176 | + |
| 177 | +```bash |
| 178 | +conan create all --version 14 -o "*:local_path=/path/to/gcc-toolchain/" |
| 179 | +``` |
| 180 | + |
| 181 | +### `default_arch` (Default: `True`) |
| 182 | + |
| 183 | +Automatically inject appropriate `-mcpu` and `-mfloat-abi` flags for the `arch` |
| 184 | +defined in your build target profile. |
| 185 | + |
| 186 | +Examples for ARM Cortex-M: |
| 187 | + |
| 188 | +- For `cortex-m4`: |
| 189 | + - `-mcpu=cortex-m4` |
| 190 | + - `-mfloat-abi=soft` |
| 191 | +- For `cortex-m4f`: |
| 192 | + - `-mcpu=cortex-m4` |
| 193 | + - `-mfloat-abi=hard` |
| 194 | + - `-mfpu=fpv4-sp-d16` |
| 195 | + |
| 196 | +### `lto` (Default: `False` for GCC 14) |
| 197 | + |
| 198 | +Enable Link-Time Optimization with `-flto`. |
| 199 | + |
| 200 | +> [!WARNING] |
| 201 | +> LTO is disabled by default for GCC 14 for ARM embedded targets. ZSTD LTO |
| 202 | +> compression support is enabled for the Linux ARM toolchain but not for macOS. |
| 203 | +> This causes errors when object files built on Linux are linked on macOS: |
| 204 | +> |
| 205 | +> ```plaintext |
| 206 | +> lto1: fatal error: compiler does not support ZSTD LTO compression |
| 207 | +> compilation terminated. |
| 208 | +> ``` |
| 209 | +
|
| 210 | +### `fat_lto` (Default: `True`) |
| 211 | +
|
| 212 | +Enable `-ffat-lto-objects` for compatibility with linkers that don't support LTO. |
| 213 | +This option is ignored if `lto` is not enabled. |
| 214 | +
|
| 215 | +### `function_sections` (Default: `True`) |
| 216 | +
|
| 217 | +Enable `-ffunction-sections` to place each function in its own section for |
| 218 | +better garbage collection at link time. |
| 219 | +
|
| 220 | +### `data_sections` (Default: `True`) |
| 221 | +
|
| 222 | +Enable `-fdata-sections` to place each data item in its own section for better |
| 223 | +garbage collection at link time. |
| 224 | +
|
| 225 | +### `gc_sections` (Default: `True`) |
| 226 | +
|
| 227 | +Enable garbage collection of unused sections. Uses `-Wl,--gc-sections` linker |
| 228 | +flag. |
| 229 | +
|
| 230 | +### `default_libc` (Default: `True`) |
| 231 | +
|
| 232 | +Inject `--specs=nosys.specs` to linker arguments. This provides weak stubs for |
| 233 | +newlib libc APIs like `exit()`, `kill()`, `sbrk()`, allowing binaries to link |
| 234 | +without defining all libc APIs upfront. |
| 235 | +
|
| 236 | +### `lto_compression_level` (Default: `0`) |
| 237 | +
|
| 238 | +Compression level for LTO objects. Accepts 0-19 for zstd or 0-9 for zlib. |
| 239 | +
|
| 240 | +## 🎯 Supported ARM Cortex-M Targets |
| 241 | +
|
| 242 | +The following embedded ARM Cortex-M architectures are fully supported: |
| 243 | +
|
| 244 | +- cortex-m0 |
| 245 | +- cortex-m0plus |
| 246 | +- cortex-m1 |
| 247 | +- cortex-m3 |
| 248 | +- cortex-m4 |
| 249 | +- cortex-m4f |
| 250 | +- cortex-m7 |
| 251 | +- cortex-m7f |
| 252 | +- cortex-m7d |
| 253 | +- cortex-m23 |
| 254 | +- cortex-m33 |
| 255 | +- cortex-m33f |
| 256 | +- cortex-m35p |
| 257 | +- cortex-m35pf |
| 258 | +- cortex-m55 |
| 259 | +- cortex-m85 |
| 260 | +
|
| 261 | +> [!NOTE] |
| 262 | +> The architecture names may have trailing characters indicating floating point |
| 263 | +> support: |
| 264 | +> |
| 265 | +> - `f` indicates single precision (32-bit) hard float |
| 266 | +> - `d` indicates double precision (64-bit) hard float |
| 267 | +
|
| 268 | +## ✨ Adding New Versions of GCC |
| 269 | +
|
| 270 | +If you'd like to add support for a new GCC version, follow these instructions |
| 271 | +(replace `XY.Z` with the correct version): |
| 272 | +
|
| 273 | +### 1. Update `config.yml` |
| 274 | +
|
| 275 | +Add the version to `/config.yml`: |
| 276 | +
|
| 277 | +```yaml |
| 278 | +versions: |
| 279 | + "14": |
| 280 | + folder: "all" |
| 281 | + "XY.Z": |
| 282 | + folder: "all" |
| 283 | +``` |
| 284 | +
|
| 285 | +### 2. Add Workflow File |
| 286 | + |
| 287 | +Add `.github/workflows/XY.Z.yml`: |
| 288 | + |
| 289 | +```yaml |
| 290 | +name: 🚀 XY.Z Deploy |
| 291 | + |
| 292 | +on: |
| 293 | + workflow_dispatch: |
| 294 | + pull_request: |
| 295 | + push: |
| 296 | + branches: |
| 297 | + - main |
| 298 | + |
| 299 | +jobs: |
| 300 | + deploy: |
| 301 | + uses: ./.github/workflows/deploy.yml |
| 302 | + with: |
| 303 | + version: "XY.Z" |
| 304 | + secrets: inherit |
| 305 | +``` |
| 306 | +
|
| 307 | +### 3. Add Profile |
| 308 | +
|
| 309 | +Add profile `gcc-XY.Z` to `/conan/profiles/v1/`: |
| 310 | + |
| 311 | +```jinja2 |
| 312 | +{% set detected_os = detect_api.detect_os() %} |
| 313 | +{% set detected_arch = detect_api.detect_arch() %} |
| 314 | +
|
| 315 | +[settings] |
| 316 | +os={{ detected_os }} |
| 317 | +arch={{ detected_arch }} |
| 318 | +build_type=Release |
| 319 | +compiler=gcc |
| 320 | +compiler.cppstd=23 |
| 321 | +compiler.libcxx=libstdc++11 |
| 322 | +compiler.version=XY |
| 323 | +
|
| 324 | +[tool_requires] |
| 325 | +multiarch-gnu-toolchain/XY.Z |
| 326 | +``` |
| 327 | + |
| 328 | +### 4. Update `conandata.yml` |
| 329 | + |
| 330 | +Add download URLs and SHA256 checksums for native and ARM cross-compiler |
| 331 | +binaries in `all/conandata.yml`: |
| 332 | + |
| 333 | +```yaml |
| 334 | +sources: |
| 335 | + "XY.Z": |
| 336 | + "native": |
| 337 | + "Linux": |
| 338 | + "x86_64": |
| 339 | + url: "" |
| 340 | + sha256: "" |
| 341 | + "armv8": |
| 342 | + url: "" |
| 343 | + sha256: "" |
| 344 | + "Windows": |
| 345 | + "x86_64": |
| 346 | + url: "" |
| 347 | + sha256: "" |
| 348 | + "arm-none-eabi": |
| 349 | + "Linux": |
| 350 | + "x86_64": |
| 351 | + url: "" |
| 352 | + sha256: "" |
| 353 | + "armv8": |
| 354 | + url: "" |
| 355 | + sha256: "" |
| 356 | + "Macos": |
| 357 | + "x86_64": |
| 358 | + url: "" |
| 359 | + sha256: "" |
| 360 | + "armv8": |
| 361 | + url: "" |
| 362 | + sha256: "" |
| 363 | + "Windows": |
| 364 | + "x86_64": |
| 365 | + url: "" |
| 366 | + sha256: "" |
| 367 | +``` |
| 368 | + |
| 369 | +### 5. Test the Package |
| 370 | + |
| 371 | +```bash |
| 372 | +# Test native build |
| 373 | +conan create all --version=XY.Z --build-require |
| 374 | +
|
| 375 | +# Test ARM cross-compilation |
| 376 | +conan create all --version=XY.Z --build-require -pr:h gcc-XY.Z -pr cortex-m4f |
| 377 | +``` |
| 378 | + |
| 379 | +### 6. Submit a Pull Request |
| 380 | + |
| 381 | +Submit a PR with title `:sparkles: Add support for GCC XY.Z`. |
| 382 | + |
| 383 | +## 🔖 Interpreting Versions |
| 384 | + |
| 385 | +The package version represents the major GCC version. For example, version "14" |
| 386 | +uses GCC 14.2.0 binaries. |
| 387 | + |
| 388 | +## 🤝 Contributing |
| 389 | + |
| 390 | +Contributions are welcome! Please ensure: |
| 391 | + |
| 392 | +1. All tests pass on supported platforms |
| 393 | +2. Documentation is updated for new features |
| 394 | +3. Profiles are added for new versions |
| 395 | + |
| 396 | +## 📄 License |
| 397 | + |
| 398 | +This project is licensed under the Apache 2.0 License - see the LICENSE file |
| 399 | +for details. |
0 commit comments