diff --git a/.github/workflows/qemu-test.yml b/.github/workflows/qemu-test.yml index 545ef16..9efa83e 100644 --- a/.github/workflows/qemu-test.yml +++ b/.github/workflows/qemu-test.yml @@ -31,13 +31,25 @@ jobs: ovmf \ mtools \ xorriso \ - imagemagick + imagemagick \ + python3 \ + python3-pip + + # Install Conan + pip3 install conan + + # Configure Conan + conan profile detect --force + + - name: Install Conan dependencies + run: | + conan install . --build=missing - name: Configure CMake run: | mkdir -p build cd build - cmake .. + cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake - name: Build bootloader and kernel run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b95a83..9908761 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,13 +29,25 @@ jobs: qemu-system-x86 \ ovmf \ mtools \ - xorriso + xorriso \ + python3 \ + python3-pip + + # Install Conan + pip3 install conan + + # Configure Conan + conan profile detect --force + + - name: Install Conan dependencies + run: | + conan install . --build=missing - name: Configure CMake run: | mkdir -p build cd build - cmake .. + cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake - name: Build bootloader and kernel run: | diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9c36d61..20f373d 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -22,13 +22,23 @@ jobs: set -e # Exit on any error sudo apt-get update - sudo apt-get install -y build-essential cmake + sudo apt-get install -y build-essential cmake python3 python3-pip + + # Install Conan + pip3 install conan + + # Configure Conan + conan profile detect --force + + - name: Install Conan dependencies + run: | + conan install . --build=missing - name: Configure CMake run: | mkdir -p build cd build - cmake .. + cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake - name: Build unit tests run: | diff --git a/Dockerfile b/Dockerfile index e5e8365..320e0ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN apt-get update && apt-get install -y \ mtools \ xorriso \ dosfstools \ - # Python for build scripts + # Python for build scripts and Conan python3 \ python3-pip \ # Additional utilities @@ -41,6 +41,12 @@ RUN apt-get update && apt-get install -y \ file \ && rm -rf /var/lib/apt/lists/* +# Install Conan package manager +RUN pip3 install --no-cache-dir conan + +# Detect and configure Conan profile +RUN conan profile detect --force + # Create directory structure for dependencies RUN mkdir -p /metalos/deps/firmware \ /metalos/deps/ovmf \ diff --git a/README.md b/README.md index 439a12d..95d45af 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,21 @@ ninja qemu ### Conan (With Package Management) ```bash +# First time: install Conan and setup profile +pip3 install conan +conan profile detect --force + +# Install dependencies and generate toolchain (Release build by default) +conan install . --build=missing + +# Configure and build mkdir build && cd build -conan install .. --build=missing cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake -G Ninja ninja + +# Note: For Debug build, use: +# conan install . --build=missing -s build_type=Debug +# cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Debug/generators/conan_toolchain.cmake -G Ninja ``` ### Docker Build (Recommended for Consistency) diff --git a/docs/BUILD.md b/docs/BUILD.md index c3af994..f28521e 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -36,6 +36,7 @@ cmake --build . --target qemu The Docker image includes: - **Build tools**: GCC, NASM, CMake, Meson +- **Conan**: Package manager for C/C++ dependencies - **QEMU**: For testing with UEFI firmware - **OVMF**: UEFI firmware for QEMU - **Dependency management**: Scripts to download AMD firmware, Mesa RADV, QT6 @@ -80,12 +81,21 @@ If you prefer to build natively without Docker: - UEFI firmware for QEMU - Required for UEFI boot testing +7. **Conan** (for dependency management) + - Package manager for C/C++ projects + - Version 2.0 or later + - Optional but recommended + ### Installing Prerequisites on Ubuntu/Debian ```bash # Install basic build tools sudo apt-get update -sudo apt-get install -y build-essential nasm qemu-system-x86 ovmf mtools xorriso +sudo apt-get install -y build-essential nasm qemu-system-x86 ovmf mtools xorriso cmake python3 python3-pip + +# Install Conan (optional but recommended) +pip3 install conan +conan profile detect --force # Install cross-compiler prerequisites sudo apt-get install -y libgmp-dev libmpfr-dev libmpc-dev texinfo @@ -97,13 +107,21 @@ sudo apt-get install -y libgmp-dev libmpfr-dev libmpc-dev texinfo ### Installing Prerequisites on Arch Linux ```bash -sudo pacman -S base-devel nasm qemu-full edk2-ovmf mtools xorriso +sudo pacman -S base-devel nasm qemu-full edk2-ovmf mtools xorriso cmake python python-pip + +# Install Conan (optional but recommended) +pip install conan +conan profile detect --force ``` ### Installing Prerequisites on macOS ```bash -brew install nasm qemu x86_64-elf-gcc x86_64-elf-binutils +brew install nasm qemu x86_64-elf-gcc x86_64-elf-binutils cmake python3 + +# Install Conan (optional but recommended) +pip3 install conan +conan profile detect --force ``` ## Building the Bootloader @@ -302,8 +320,66 @@ mkdir build && cd build cmake .. ``` +## Testing Conan Integration + +To verify that Conan is properly integrated and working: + +```bash +# Run the Conan integration test +./scripts/test-conan-build.sh +``` + +This test script will: +1. Verify Conan installation +2. Check/create Conan profile +3. Install dependencies +4. Generate Conan toolchain +5. Configure CMake with Conan +6. Validate the integration + ## Troubleshooting +### Conan Not Found +If you get "conan: command not found": +```bash +# Install Conan +pip3 install conan + +# Verify installation +conan --version + +# Create profile +conan profile detect --force +``` + +### Conan Profile Issues +If Conan complains about missing profile: +```bash +# Detect and create default profile +conan profile detect --force + +# Verify profile exists +conan profile show default +``` + +### Conan Toolchain Not Found +If CMake can't find the Conan toolchain: +```bash +# Make sure to run conan install first +conan install . --build=missing + +# The toolchain location depends on the build type: +# - Release (default): build/Release/generators/conan_toolchain.cmake +# - Debug: build/Debug/generators/conan_toolchain.cmake + +# For Release build (default): +cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake + +# For Debug build: +conan install . --build=missing -s build_type=Debug +cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Debug/generators/conan_toolchain.cmake +``` + ### Cross-Compiler Not Found If you get errors about missing cross-compiler: 1. Check that x86_64-elf-gcc is in your PATH diff --git a/docs/BUILD_SYSTEMS.md b/docs/BUILD_SYSTEMS.md index 961c213..1464e8f 100644 --- a/docs/BUILD_SYSTEMS.md +++ b/docs/BUILD_SYSTEMS.md @@ -22,10 +22,23 @@ ninja qemu # Test in QEMU ### Using Conan + CMake ```bash +# First time: install Conan and setup profile +pip3 install conan +conan profile detect --force + +# Install dependencies (generates toolchain files - Release by default) +conan install . --build=missing + +# Configure with Conan toolchain mkdir build && cd build -conan install .. --build=missing -cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake +cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake + +# Build cmake --build . + +# Note: The toolchain path matches the build type: +# - Release (default): build/Release/generators/conan_toolchain.cmake +# - Debug: build/Debug/generators/conan_toolchain.cmake (use -s build_type=Debug) ``` ## Build System Comparison @@ -160,18 +173,23 @@ conan profile detect --force #### Build Commands ```bash -# Create build directory +# Install dependencies (generates toolchain in build//generators/) +# Default is Release build type +conan install . --build=missing + +# Alternative: Install with specific build type +conan install . --build=missing -s build_type=Debug # Generates in build/Debug/generators/ +conan install . --build=missing -s build_type=Release # Generates in build/Release/generators/ + +# Create build directory and configure with Conan-generated toolchain +# Note: Toolchain path must match the build type used in conan install mkdir build && cd build -# Install dependencies (currently none, but ready for future) -conan install .. --build=missing +# For Release build (default) +cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Release/generators/conan_toolchain.cmake -# Alternative: Install with specific settings -conan install .. --build=missing -s build_type=Debug -conan install .. --build=missing -s build_type=Release - -# Configure with Conan-generated toolchain -cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake +# Or for Debug build +cmake .. -DCMAKE_TOOLCHAIN_FILE=../build/Debug/generators/conan_toolchain.cmake # Build cmake --build . @@ -187,13 +205,19 @@ conan build . --build-folder=build - ✅ Version management - ✅ Cross-platform package management - ✅ Integration with CMake and other build systems +- ✅ **Recommended for CI/CD** - ensures consistent builds #### Disadvantages - ❌ Requires Python and Conan -- ❌ Additional complexity -- ❌ Currently overkill (we have no dependencies yet) +- ❌ Additional setup step - ❌ Learning curve +#### When to Use +- ✅ **CI/CD pipelines** (all workflows now use Conan) +- ✅ **Production builds** requiring reproducibility +- ✅ **When adding external dependencies** (QT6, Mesa RADV in the future) +- ✅ **Cross-platform development** needing consistent dependencies + --- ## Which Build System Should I Use? @@ -214,26 +238,31 @@ cd build-ninja && ninja && ninja qemu - Configure your IDE to use the CMakeLists.txt ### For CI/CD -**Use: Make or CMake** +**Use: Conan + CMake (Recommended)** ```bash # GitHub Actions, GitLab CI, etc. -make all && make test - -# Or with CMake -cmake -B build -G Ninja +# All MetalOS CI workflows now use Conan +conan install . --build=missing +cmake -B build -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake cmake --build build ctest --test-dir build ``` +Benefits: +- ✅ Reproducible builds across different CI runners +- ✅ Consistent dependency versions +- ✅ Future-proof for when we add dependencies + ### For Cross-Platform Development -**Use: CMake + Ninja** +**Use: Conan + CMake + Ninja** ```bash # Works on Linux, macOS, Windows -cmake -G Ninja -B build +conan install . --build=missing +cmake -G Ninja -B build -DCMAKE_TOOLCHAIN_FILE=build/Release/generators/conan_toolchain.cmake cmake --build build ``` -### For Projects with Dependencies (Future) +### For Projects with Dependencies (Current & Future) **Use: Conan + CMake** ```bash # When we add QT6, Mesa RADV, etc. diff --git a/scripts/test-conan-build.sh b/scripts/test-conan-build.sh new file mode 100755 index 0000000..6b81d0d --- /dev/null +++ b/scripts/test-conan-build.sh @@ -0,0 +1,77 @@ +#!/bin/bash +# Test script for Conan integration +# This script tests that Conan is properly integrated and can build MetalOS + +set -e # Exit on any error + +echo "==========================================" +echo "MetalOS Conan Integration Test" +echo "==========================================" +echo "" + +# Check if Conan is installed +echo "1. Checking Conan installation..." +if ! command -v conan &> /dev/null; then + echo "Error: Conan is not installed" + echo "Install with: pip3 install conan" + exit 1 +fi +conan --version +echo "✓ Conan is installed" +echo "" + +# Check if Conan profile exists +echo "2. Checking Conan profile..." +if ! conan profile show default &> /dev/null; then + echo "Creating default Conan profile..." + conan profile detect --force +fi +echo "✓ Conan profile exists" +echo "" + +# Clean any previous build artifacts +echo "3. Cleaning previous build artifacts..." +rm -rf build build-conan-test CMakeUserPresets.json +echo "✓ Clean complete" +echo "" + +# Install dependencies with Conan +echo "4. Installing dependencies with Conan..." +conan install . --build=missing +echo "✓ Dependencies installed" +echo "" + +# Verify toolchain was generated +echo "5. Verifying Conan toolchain generation..." +TOOLCHAIN_PATH="" +if [ -f "build/Release/generators/conan_toolchain.cmake" ]; then + TOOLCHAIN_PATH="build/Release/generators/conan_toolchain.cmake" +elif [ -f "build/Debug/generators/conan_toolchain.cmake" ]; then + TOOLCHAIN_PATH="build/Debug/generators/conan_toolchain.cmake" +else + echo "Error: conan_toolchain.cmake not found in build/Release/generators/ or build/Debug/generators/" + exit 1 +fi +echo "✓ Conan toolchain generated at: $TOOLCHAIN_PATH" +echo "" + +# Configure with CMake using Conan toolchain +echo "6. Configuring CMake with Conan toolchain..." +mkdir -p build-conan-test +cd build-conan-test +cmake .. -DCMAKE_TOOLCHAIN_FILE="../$TOOLCHAIN_PATH" +cd .. +echo "✓ CMake configuration successful" +echo "" + +# Clean up test build directory +echo "7. Cleaning up test artifacts..." +rm -rf build-conan-test build CMakeUserPresets.json +echo "✓ Cleanup complete" +echo "" + +echo "==========================================" +echo "Conan Integration Test: PASSED ✓" +echo "==========================================" +echo "" +echo "Conan is properly integrated and working!"