From 2131451b0e29b9c8637388cd9a0eeef63edf06ac Mon Sep 17 00:00:00 2001 From: Marco Zanzottera Date: Tue, 7 Oct 2025 12:43:42 +0200 Subject: [PATCH] Add devcontainer and build script --- .devcontainer/Dockerfile | 103 ++++++++++++++++++++++++++++++++ .devcontainer/build-lavinium.sh | 36 +++++++++++ .devcontainer/devcontainer.json | 8 +++ 3 files changed, 147 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/build-lavinium.sh create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..f2ce32a2f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,103 @@ +FROM ubuntu:noble + +# Install sudo +RUN apt update \ + && apt install -y sudo \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Add ubuntu user to the sudoers file +RUN echo ubuntu ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/ubuntu \ + && chmod 0440 /etc/sudoers.d/ubuntu + +# Install dependencies for riscv-gnu-toolchain +RUN apt update \ + && apt install -y \ + autoconf \ + automake \ + autotools-dev \ + bc \ + bison \ + build-essential \ + cmake \ + curl \ + flex \ + gawk \ + git \ + gperf \ + libexpat-dev \ + libglib2.0-dev \ + libgmp-dev \ + libmpc-dev \ + libmpfr-dev \ + libslirp-dev \ + libtool \ + ninja-build \ + patchutils \ + python3 \ + python3-pip \ + python3-tomli \ + texinfo \ + zlib1g-dev \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Install riscv-gnu-toolchain from source +RUN git clone https://github.com/riscv/riscv-gnu-toolchain \ + && cd riscv-gnu-toolchain \ + && ./configure --prefix=/opt/riscv --with-arch=rv32im --with-abi=ilp32 --enable-llvm --disable-linux \ + && make -j$(nproc) all \ + && cd .. \ + && rm -rf riscv-gnu-toolchain + +# Install dependencies for Lavinium +RUN apt update \ + && apt install -y \ + binutils \ + bzip2 \ + coreutils \ + findutils \ + grep \ + gzip \ + libboost-all-dev \ + libbz2-dev \ + liblpsolve55-dev \ + libssl-dev \ + libxml2-dev \ + lp-solve \ + make \ + sed \ + sharutils \ + tar \ + unzip \ + xz-utils \ + zip \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Link the lpsolve library to make it available for compilation +RUN ln -sf /usr/lib/lp_solve/liblpsolve55.so /usr/lib/liblpsolve55.so + +# Install pandas to make Lavinium test.py and test_mt.py work +RUN apt update \ + && apt install -y \ + python3-pandas \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Install dependencies for llvm installer + +RUN apt update \ + && apt install -y \ + gnupg \ + lsb-release \ + software-properties-common \ + wget \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Install llvm +RUN wget https://apt.llvm.org/llvm.sh \ + && chmod +x llvm.sh \ + && ./llvm.sh all \ + && rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + +# Add llvm to PATH +ENV PATH="/usr/lib/llvm-20/bin:$PATH" + +USER ubuntu diff --git a/.devcontainer/build-lavinium.sh b/.devcontainer/build-lavinium.sh new file mode 100755 index 000000000..af520aa4c --- /dev/null +++ b/.devcontainer/build-lavinium.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -euo pipefail + +# Define build and install directories +llvm_root=$(pwd) +build_dir=$llvm_root/build +install_dir=$build_dir/install + +mkdir -p "$build_dir" +mkdir -p "$install_dir" + +# Configure CMake to build LLVM + Clang (and all LLVM tools like opt) +cmake -G Ninja -S "$llvm_root/llvm" -B "$build_dir" \ + -DCMAKE_INSTALL_PREFIX="$install_dir" \ + -DCMAKE_BUILD_TYPE=Debug \ + \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_ASM_COMPILER=clang \ + -DCMAKE_LINKER=lld \ + \ + -DLLVM_ENABLE_PROJECTS="clang;lld" \ + -DLLVM_TARGETS_TO_BUILD="ARM;RISCV" \ + -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" \ + -DLLVM_ENABLE_EH=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_USE_SPLIT_DWARF=ON \ + -DLLVM_OPTIMIZED_TABLEGEN=ON \ + -DLLVM_PARALLEL_LINK_JOBS=4 \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_BUILD_TESTS=OFF + +# Build and install +ninja -C "$build_dir" install diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..33cbd8087 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,8 @@ +{ + "name": "lavinium-dev", + "build": { "dockerfile": "Dockerfile" }, + "runArgs": [ + "--name", + "lavinium-dev" + ] +} \ No newline at end of file