mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Adapt Docker script and Dockerfile (#1347)
Adapt Docker script and Dockerfile
This commit is contained in:
111
.github/workflows/main.yml
vendored
111
.github/workflows/main.yml
vendored
@@ -486,6 +486,117 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: c3-ubuntu-20-${{matrix.build_type}}
|
name: c3-ubuntu-20-${{matrix.build_type}}
|
||||||
path: c3-ubuntu-20-${{matrix.build_type}}.tar.gz
|
path: c3-ubuntu-20-${{matrix.build_type}}.tar.gz
|
||||||
|
|
||||||
|
build-with-docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
ubuntu_version: [20.04, 22.04]
|
||||||
|
build_type: [Release, Debug]
|
||||||
|
llvm_version: [17, 18, 19, 20]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Make script executable
|
||||||
|
run: chmod +x ./build-with-docker.sh
|
||||||
|
|
||||||
|
- name: Run build
|
||||||
|
run: |
|
||||||
|
LLVM_VERSION=${{ matrix.llvm_version }} UBUNTU_VERSION=${{ matrix.ubuntu_version }} CMAKE_BUILD_TYPE=${{ matrix.build_type }} ./build-with-docker.sh
|
||||||
|
|
||||||
|
- name: Compile and run some examples
|
||||||
|
run: |
|
||||||
|
cd resources
|
||||||
|
../build/c3c compile examples/base64.c3
|
||||||
|
../build/c3c compile examples/binarydigits.c3
|
||||||
|
../build/c3c compile examples/brainfk.c3
|
||||||
|
../build/c3c compile examples/factorial_macro.c3
|
||||||
|
../build/c3c compile examples/fasta.c3
|
||||||
|
../build/c3c compile examples/gameoflife.c3
|
||||||
|
../build/c3c compile examples/hash.c3
|
||||||
|
../build/c3c compile-only examples/levenshtein.c3
|
||||||
|
../build/c3c compile examples/load_world.c3
|
||||||
|
../build/c3c compile-only examples/map.c3
|
||||||
|
../build/c3c compile examples/mandelbrot.c3
|
||||||
|
../build/c3c compile examples/plus_minus.c3
|
||||||
|
../build/c3c compile examples/nbodies.c3
|
||||||
|
../build/c3c compile examples/spectralnorm.c3
|
||||||
|
../build/c3c compile examples/swap.c3
|
||||||
|
../build/c3c compile examples/contextfree/boolerr.c3
|
||||||
|
../build/c3c compile examples/contextfree/dynscope.c3
|
||||||
|
../build/c3c compile examples/contextfree/guess_number.c3
|
||||||
|
../build/c3c compile examples/contextfree/multi.c3
|
||||||
|
../build/c3c compile examples/contextfree/cleanup.c3
|
||||||
|
../build/c3c compile-run examples/hello_world_many.c3
|
||||||
|
../build/c3c compile-run examples/time.c3
|
||||||
|
../build/c3c compile-run examples/fannkuch-redux.c3
|
||||||
|
../build/c3c compile-run examples/contextfree/boolerr.c3
|
||||||
|
../build/c3c compile-run examples/load_world.c3
|
||||||
|
../build/c3c compile-run examples/process.c3
|
||||||
|
../build/c3c compile-run examples/ls.c3
|
||||||
|
../build/c3c compile-run --linker=builtin linux_stack.c3
|
||||||
|
../build/c3c compile-run linux_stack.c3
|
||||||
|
../build/c3c compile-run examples/args.c3 -- foo -bar "baz baz"
|
||||||
|
|
||||||
|
- name: Compile run unit tests
|
||||||
|
run: |
|
||||||
|
cd test
|
||||||
|
../build/c3c compile-test unit
|
||||||
|
|
||||||
|
- name: Build testproject
|
||||||
|
run: |
|
||||||
|
cd resources/testproject
|
||||||
|
../../build/c3c run --debug-log
|
||||||
|
|
||||||
|
- name: Test WASM
|
||||||
|
run: |
|
||||||
|
cd resources/testfragments
|
||||||
|
../../build/c3c compile --reloc=none --target wasm32 -g0 --link-libc=no --no-entry -Os wasm4.c3
|
||||||
|
|
||||||
|
- name: Install QEMU and Risc-V toolchain
|
||||||
|
run: |
|
||||||
|
sudo apt-get install opensbi qemu-system-misc u-boot-qemu gcc-riscv64-unknown-elf
|
||||||
|
|
||||||
|
- name: Compile and run Baremetal Risc-V Example
|
||||||
|
run: |
|
||||||
|
cd resources/examples/embedded/riscv-qemu
|
||||||
|
make C3C_PATH=../../../../build/ run
|
||||||
|
|
||||||
|
- name: Build testproject direct linker
|
||||||
|
run: |
|
||||||
|
cd resources/testproject
|
||||||
|
../../build/c3c run --debug-log --linker=builtin
|
||||||
|
|
||||||
|
- name: Init a library & a project
|
||||||
|
run: |
|
||||||
|
./build/c3c init-lib mylib
|
||||||
|
ls mylib.c3l
|
||||||
|
./build/c3c init myproject
|
||||||
|
ls myproject
|
||||||
|
|
||||||
|
- name: run compiler tests
|
||||||
|
run: |
|
||||||
|
cd test
|
||||||
|
python3 src/tester.py ../build/c3c test_suite/
|
||||||
|
|
||||||
|
- name: bundle_output
|
||||||
|
run: |
|
||||||
|
mkdir c3
|
||||||
|
cp -r lib c3
|
||||||
|
cp msvc_build_libraries.py c3
|
||||||
|
cp build/c3c c3
|
||||||
|
tar czf c3-ubuntu-${{matrix.build_type}}.tar.gz c3
|
||||||
|
|
||||||
|
- name: upload artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: c3-ubuntu-${{ matrix.ubuntu_version }}-${{matrix.build_type}}
|
||||||
|
path: c3-ubuntu-${{matrix.build_type}}.tar.gz
|
||||||
|
|
||||||
build-mac:
|
build-mac:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|||||||
@@ -1,43 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## build-with-docker.sh
|
|
||||||
## @author gdm85
|
|
||||||
## @modified by Kenta
|
|
||||||
##
|
|
||||||
## Script to build c3c for Ubuntu 22
|
|
||||||
##
|
|
||||||
#
|
|
||||||
|
|
||||||
read -p "Select Build Type: Debug/Release: " config
|
: ${DOCKER:=docker}
|
||||||
|
: ${IMAGE:="c3c-builder"}
|
||||||
|
: ${CMAKE_BUILD_TYPE:=Release}
|
||||||
|
: ${LLVM_VERSION:=18}
|
||||||
|
: ${UBUNTU_VERSION:="22.04"}
|
||||||
|
: ${CMAKE_VERSION:="3.20.0"}
|
||||||
|
|
||||||
set -e
|
cd docker || exit 1 # Exit if the 'docker' directory doesn't exist
|
||||||
|
|
||||||
DOCKER=docker
|
$DOCKER build \
|
||||||
DOCKER_RUN=""
|
--build-arg LLVM_VERSION=$LLVM_VERSION \
|
||||||
IMAGE="c3c-builder"
|
--build-arg CMAKE_VERSION=$CMAKE_VERSION \
|
||||||
if type podman 2>/dev/null >/dev/null; then
|
--build-arg UBUNTU_VERSION=$UBUNTU_VERSION \
|
||||||
DOCKER=podman
|
-t $IMAGE .
|
||||||
DOCKER_RUN="--userns=keep-id"
|
|
||||||
IMAGE="localhost/$IMAGE"
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Docker image build failed. Exiting."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $config == "Debug" ]; then
|
|
||||||
CMAKE_BUILD_TYPE=Debug
|
|
||||||
else
|
|
||||||
CMAKE_BUILD_TYPE="$config"
|
|
||||||
fi
|
|
||||||
|
|
||||||
UBUNTU_VERSION="22.10"
|
|
||||||
LLVM_VERSION="15"
|
|
||||||
|
|
||||||
IMAGE="$IMAGE:22"
|
|
||||||
|
|
||||||
cd docker && $DOCKER build -t $IMAGE\
|
|
||||||
--build-arg DEPS="llvm-$LLVM_VERSION-dev liblld-$LLVM_VERSION-dev clang-$LLVM_VERSION libllvm$LLVM_VERSION llvm-$LLVM_VERSION-runtime" \
|
|
||||||
--build-arg UBUNTU_VERSION="$UBUNTU_VERSION" .
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
rm -rf build bin
|
rm -rf build bin
|
||||||
mkdir -p build bin
|
mkdir -p build bin
|
||||||
|
|
||||||
exec $DOCKER run -ti --rm --tmpfs=/tmp $DOCKER_RUN -v "$PWD":/home/c3c/source -w /home/c3c/source $IMAGE bash -c \
|
chmod -R 777 build bin
|
||||||
"cd build && cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DC3_LLVM_VERSION=$LLVM_VERSION .. && cmake --build . && mv c3c lib ../bin/"
|
|
||||||
|
exec $DOCKER run -i --rm \
|
||||||
|
-v "$PWD":/home/c3c/source \
|
||||||
|
-w /home/c3c/source $IMAGE bash -c \
|
||||||
|
"cmake -S . -B build \
|
||||||
|
-G Ninja \
|
||||||
|
-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
|
||||||
|
-DCMAKE_C_COMPILER=clang-$LLVM_VERSION \
|
||||||
|
-DCMAKE_CXX_COMPILER=clang++-$LLVM_VERSION \
|
||||||
|
-DCMAKE_LINKER=lld-$LLVM_VERSION \
|
||||||
|
-DCMAKE_OBJCOPY=llvm-objcopy-$LLVM_VERSION \
|
||||||
|
-DCMAKE_STRIP=llvm-strip-$LLVM_VERSION \
|
||||||
|
-DCMAKE_DLLTOOL=llvm-dlltool-$LLVM_VERSION \
|
||||||
|
-DC3_LLVM_VERSION=auto && \
|
||||||
|
cmake --build build && \
|
||||||
|
cp -r build/c3c build/lib bin"
|
||||||
@@ -1,16 +1,49 @@
|
|||||||
|
ARG UBUNTU_VERSION=22.04
|
||||||
|
FROM ubuntu:${UBUNTU_VERSION}
|
||||||
|
|
||||||
ARG UBUNTU_VERSION
|
ARG LLVM_VERSION=18
|
||||||
FROM ubuntu:$UBUNTU_VERSION
|
ENV LLVM_DEV_VERSION=20
|
||||||
|
|
||||||
ARG DEPS
|
ARG CMAKE_VERSION=3.20
|
||||||
|
|
||||||
RUN export DEBIAN_FRONTEND=noninteractive && export TERM=xterm && apt-get update && apt-get install -y build-essential cmake zlib1g zlib1g-dev \
|
RUN apt-get update && apt-get install -y wget gnupg software-properties-common zlib1g zlib1g-dev python3 ninja-build curl g++ && \
|
||||||
$DEPS && \
|
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-$CMAKE_VERSION-linux-x86_64.sh && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
mkdir -p /opt/cmake && \
|
||||||
|
sh cmake-${CMAKE_VERSION}-linux-x86_64.sh --prefix=/opt/cmake --skip-license && \
|
||||||
|
rm cmake-${CMAKE_VERSION}-linux-x86_64.sh && \
|
||||||
|
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
|
||||||
|
|
||||||
ARG GID=1000
|
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
|
||||||
ARG UID=1000
|
if [ "${LLVM_VERSION}" -lt 18 ]; then \
|
||||||
|
add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${LLVM_VERSION} main" && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y -t llvm-toolchain-focal-${LLVM_VERSION} \
|
||||||
|
libpolly-${LLVM_VERSION}-dev \
|
||||||
|
clang-${LLVM_VERSION} llvm-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev \
|
||||||
|
lld-${LLVM_VERSION} liblld-${LLVM_VERSION}-dev libmlir-${LLVM_VERSION} \
|
||||||
|
libmlir-${LLVM_VERSION}-dev mlir-${LLVM_VERSION}-tools; \
|
||||||
|
elif [ "${LLVM_VERSION}" -lt "${LLVM_DEV_VERSION}" ]; then \
|
||||||
|
add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${LLVM_VERSION} main" && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y -t llvm-toolchain-focal-${LLVM_VERSION} \
|
||||||
|
libpolly-${LLVM_VERSION}-dev \
|
||||||
|
clang-${LLVM_VERSION} clang++-${LLVM_VERSION} llvm-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev \
|
||||||
|
lld-${LLVM_VERSION} liblld-${LLVM_VERSION}-dev; \
|
||||||
|
else \
|
||||||
|
add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main" && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y -t llvm-toolchain-focal \
|
||||||
|
libpolly-${LLVM_VERSION}-dev \
|
||||||
|
clang-${LLVM_VERSION} llvm-${LLVM_VERSION} llvm-${LLVM_VERSION}-dev \
|
||||||
|
lld-${LLVM_VERSION} liblld-${LLVM_VERSION}-dev; \
|
||||||
|
fi && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
RUN groupadd -o --gid=$GID c3c && useradd --gid=$GID --uid=$GID --create-home --shell /bin/bash c3c
|
RUN groupadd -g 1337 c3c && \
|
||||||
|
useradd -m -u 1337 -g c3c c3c
|
||||||
|
|
||||||
|
# Add cmake to PATH for user c3c
|
||||||
USER c3c
|
USER c3c
|
||||||
|
ENV PATH="/opt/cmake/bin:${PATH}"
|
||||||
|
|
||||||
|
WORKDIR /home/c3c
|
||||||
Reference in New Issue
Block a user