diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index ecab852..f7840b3 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -1,8 +1,11 @@ +# Copyright 2024, Giordano Salvador +# SPDX-License-Identifier: BSD-3-Clause + name: Build-and-test on: - workflow_dispatch: + workflow_call: branches: [ "main" ] inputs: build_mode: @@ -13,31 +16,22 @@ on: options: - debug - release + distro: + description: OS distribution name + required: true + type: string + os_ver: + description: OS distribution version + required: true + type: string + os: + description: OS string identifier + required: true + type: string jobs: - build-and-test-ubuntu-2404: - env: - DISTRO: ubuntu - OS: ubuntu-2404 - runs-on: ubuntu-24.04 - steps: - - - name: Checkout source - uses: actions/checkout@v4 - - - name: Build source container - run: | - docker build \ - -f container/Containerfile.${{ env.DISTRO }} \ - -t ${{ env.OS }}-calcc-${{ inputs.build_mode }} \ - ${{ inputs.build_mode == 'release' && '--build-arg=BUILD_MODE=--release' || '' }} \ - . - - build-and-test-fedora-40: - env: - DISTRO: fedora - OS: fedora-40 + build-and-test: runs-on: ubuntu-24.04 steps: @@ -47,7 +41,7 @@ jobs: - name: Build source container run: | docker build \ - -f container/Containerfile.${{ env.DISTRO }} \ + -f container/Containerfile.${{ env.DISTRO }}${{ env.OS_VER }} \ -t ${{ env.OS }}-calcc-${{ inputs.build_mode }} \ ${{ inputs.build_mode == 'release' && '--build-arg=BUILD_MODE=--release' || '' }} \ . diff --git a/.github/workflows/fedora-40.yaml b/.github/workflows/fedora-40.yaml new file mode 100644 index 0000000..ffdbae6 --- /dev/null +++ b/.github/workflows/fedora-40.yaml @@ -0,0 +1,34 @@ +# Copyright 2024, Giordano Salvador +# SPDX-License-Identifier: BSD-3-Clause + +name: Fedora 40 + +on: + + workflow_dispatch: + branches: [ "main" ] + paths: + - .github/workflows/build-and-test.yaml + inputs: + build_mode: + description: Build optimization level + required: true + default: debug + type: choice + options: + - debug + - release + +jobs: + + test: + env: + DISTRO: fedora + OS_VER: 40 + OS: fedora-40 + uses: ./.github/workflows/build-and-test.yaml + with: + build_mode: debug + distro: ${{ env.DISTRO }} + os_ver: ${{ env.OS_VER }} + os: ${{ env.OS }} diff --git a/.github/workflows/ubuntu-2204.yaml b/.github/workflows/ubuntu-2204.yaml new file mode 100644 index 0000000..a73a8e1 --- /dev/null +++ b/.github/workflows/ubuntu-2204.yaml @@ -0,0 +1,34 @@ +# Copyright 2024, Giordano Salvador +# SPDX-License-Identifier: BSD-3-Clause + +name: Ubuntu 22.04 + +on: + + workflow_dispatch: + branches: [ "main" ] + paths: + - .github/workflows/build-and-test.yaml + inputs: + build_mode: + description: Build optimization level + required: true + default: debug + type: choice + options: + - debug + - release + +jobs: + + test: + env: + DISTRO: ubuntu + OS_VER: 22 + OS: ubuntu-2204 + uses: ./.github/workflows/build-and-test.yaml + with: + build_mode: debug + distro: ${{ env.DISTRO }} + os_ver: ${{ env.OS_VER }} + os: ${{ env.OS }} diff --git a/.github/workflows/ubuntu-2404.yaml b/.github/workflows/ubuntu-2404.yaml new file mode 100644 index 0000000..a4bf7c4 --- /dev/null +++ b/.github/workflows/ubuntu-2404.yaml @@ -0,0 +1,34 @@ +# Copyright 2024, Giordano Salvador +# SPDX-License-Identifier: BSD-3-Clause + +name: Ubuntu 24.04 + +on: + + workflow_dispatch: + branches: [ "main" ] + paths: + - .github/workflows/build-and-test.yaml + inputs: + build_mode: + description: Build optimization level + required: true + default: debug + type: choice + options: + - debug + - release + +jobs: + + test: + env: + DISTRO: ubuntu + OS_VER: 24 + OS: ubuntu-2404 + uses: ./.github/workflows/build-and-test.yaml + with: + build_mode: debug + distro: ${{ env.DISTRO }} + os_ver: ${{ env.OS_VER }} + os: ${{ env.OS }} diff --git a/README.md b/README.md index 7bd363f..4a992a1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Author/Maintainer: Giordano Salvador <73959795+e3m3@users.noreply.github.com> # Description (calcc language) +[![Ubuntu 22.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml) +[![Ubuntu 24.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2404.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml) +[![Fedora 40](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml) + Learning [Rust][1] [[1]] by implementing the calc langauge using the [llvm-sys][2] [[2]] crate. Implements the calc language, inspired by the [C++][3] [[3]] implementation presented by Macke and Kwan in [[4]] and [[5]]. diff --git a/container/Containerfile.fedora b/container/Containerfile.fedora40 similarity index 74% rename from container/Containerfile.fedora rename to container/Containerfile.fedora40 index 714cc6a..e995a19 100644 --- a/container/Containerfile.fedora +++ b/container/Containerfile.fedora40 @@ -14,8 +14,8 @@ RUN dnf clean -y all ENV RUST_CHANNEL=stable RUN rustup-init -y -RUN source ${CARGO_ENV} && rustup toolchain install ${RUST_CHANNEL} -RUN source ${CARGO_ENV} && rustup override set ${RUST_CHANNEL} +RUN source ${CARGO_ENV} && rustup toolchain install ${RUST_CHANNEL} +RUN source ${CARGO_ENV} && rustup override set ${RUST_CHANNEL} RUN mkdir -p ${PROJECT_DIR} RUN mkdir -p ${PROJECT_DIR}/src @@ -31,5 +31,5 @@ COPY tests ${PROJECT_DIR}/tests/ ARG BUILD_MODE= WORKDIR ${PROJECT_DIR} -RUN source ${CARGO_ENV} && cargo build --verbose ${BUILD_MODE} -RUN source ${CARGO_ENV} && cargo test --verbose ${BUILD_MODE} -- --nocapture +RUN source ${CARGO_ENV} && cargo build --verbose ${BUILD_MODE} +RUN source ${CARGO_ENV} && cargo test --verbose ${BUILD_MODE} -- --nocapture diff --git a/container/Containerfile.ubuntu b/container/Containerfile.ubuntu index 7a08eee..4bc0e3c 100644 --- a/container/Containerfile.ubuntu +++ b/container/Containerfile.ubuntu @@ -1,4 +1,4 @@ -FROM docker.io/ubuntu:24.04 +FROM docker.io/ubuntu:22.04 LABEL maintainer="Giordano Salvador <73959795+e3m3@users.noreply.github.com>" USER root @@ -10,12 +10,12 @@ ENV SSL_CONF_TMP=/etc/apt/apt.conf.d/99_tmp_ssl-verify-off.conf ENV SED_HTTPS='s%http://(.*archive|security).ubuntu.com%https://mirrors.edge.kernel.org%g' RUN echo 'Acquire::https::Verify-Peer "false";' >${SSL_CONF_TMP} && \ - sed --in-place=.orig --regexp-extended ${SED_HTTPS} /etc/apt/sources.list.d/* && \ + sed --in-place=.orig --regexp-extended ${SED_HTTPS} /etc/apt/sources.list && \ apt-get update && apt-get install ca-certificates -y && \ rm ${SSL_CONF_TMP} RUN apt-get update && apt-get upgrade -y -RUN apt-get install -y libstdc++-14-dev gcc llvm llvm-dev clang rustup python3-pip python3-venv +RUN apt-get install -y libstdc++-12-dev gcc python3-pip python3-venv curl git RUN apt-get clean ENV PYTHON_VENV_PATH=/root/.python/venv @@ -23,16 +23,26 @@ RUN python3 -m venv ${PYTHON_VENV_PATH} ENV PATH=${PYTHON_VENV_PATH}/bin:${PATH} RUN pip install lit +ENV SPACK_GIT=https://github.com/spack/spack +ENV SPACK_VER=v0.22.1 +ENV SPACK_HOME=/root/spack +ENV SPACK_SETUP=${SPACK_HOME}/share/spack/setup-env.sh +ENV LLVM_VER=18.1.3 + +RUN git clone --recursive --branch ${SPACK_VER} ${SPACK_GIT} ${SPACK_HOME} +RUN . ${SPACK_SETUP} && spack install llvm@${LLVM_VER} +clang + ENV RUST_CHANNEL=stable ENV RUSTUP_HOME=/root/.rustup ENV TOOLCHAIN=${RUST_CHANNEL}-x86_64-unknown-linux-gnu +ENV CARGO_ENV=/root/.cargo/env + +RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -o rustup-boostrap.sh && \ + sh rustup-boostrap.sh -y -RUN rustup set auto-self-update disable -RUN rustup toolchain install ${RUST_CHANNEL} -RUN rustup override set ${RUST_CHANNEL} -ENV PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/bin:${PATH} -ENV PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/libexec:${PATH} -ENV LD_LIBRARY_PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/lib:${LD_LIBRARY_PATH} +RUN . ${SPACK_SETUP} && . ${CARGO_ENV} && rustup update +RUN . ${SPACK_SETUP} && . ${CARGO_ENV} && rustup toolchain install ${RUST_CHANNEL} +RUN . ${SPACK_SETUP} && . ${CARGO_ENV} && rustup override set ${RUST_CHANNEL} RUN mkdir -p ${PROJECT_DIR} RUN mkdir -p ${PROJECT_DIR}/src @@ -48,5 +58,5 @@ COPY tests ${PROJECT_DIR}/tests/ ARG BUILD_MODE= WORKDIR ${PROJECT_DIR} -RUN cargo build --verbose ${BUILD_MODE} -RUN cargo test --verbose ${BUILD_MODE} -- --nocapture +RUN . ${SPACK_SETUP} && . ${CARGO_ENV} && cargo build --verbose ${BUILD_MODE} +RUN . ${SPACK_SETUP} && . ${CARGO_ENV} && cargo test --verbose ${BUILD_MODE} -- --nocapture diff --git a/container/Containerfile.ubuntu24 b/container/Containerfile.ubuntu24 new file mode 100644 index 0000000..7a08eee --- /dev/null +++ b/container/Containerfile.ubuntu24 @@ -0,0 +1,52 @@ +FROM docker.io/ubuntu:24.04 + +LABEL maintainer="Giordano Salvador <73959795+e3m3@users.noreply.github.com>" +USER root + +ENV TERM=xterm-256color +ENV PROJECT_DIR=${HOME}/project + +ENV SSL_CONF_TMP=/etc/apt/apt.conf.d/99_tmp_ssl-verify-off.conf +ENV SED_HTTPS='s%http://(.*archive|security).ubuntu.com%https://mirrors.edge.kernel.org%g' + +RUN echo 'Acquire::https::Verify-Peer "false";' >${SSL_CONF_TMP} && \ + sed --in-place=.orig --regexp-extended ${SED_HTTPS} /etc/apt/sources.list.d/* && \ + apt-get update && apt-get install ca-certificates -y && \ + rm ${SSL_CONF_TMP} + +RUN apt-get update && apt-get upgrade -y +RUN apt-get install -y libstdc++-14-dev gcc llvm llvm-dev clang rustup python3-pip python3-venv +RUN apt-get clean + +ENV PYTHON_VENV_PATH=/root/.python/venv +RUN python3 -m venv ${PYTHON_VENV_PATH} +ENV PATH=${PYTHON_VENV_PATH}/bin:${PATH} +RUN pip install lit + +ENV RUST_CHANNEL=stable +ENV RUSTUP_HOME=/root/.rustup +ENV TOOLCHAIN=${RUST_CHANNEL}-x86_64-unknown-linux-gnu + +RUN rustup set auto-self-update disable +RUN rustup toolchain install ${RUST_CHANNEL} +RUN rustup override set ${RUST_CHANNEL} +ENV PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/bin:${PATH} +ENV PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/libexec:${PATH} +ENV LD_LIBRARY_PATH=${RUSTUP_HOME}/toolchains/${TOOLCHAIN}/lib:${LD_LIBRARY_PATH} + +RUN mkdir -p ${PROJECT_DIR} +RUN mkdir -p ${PROJECT_DIR}/src +RUN mkdir -p ${PROJECT_DIR}/tests + +COPY Cargo.toml ${PROJECT_DIR}/ +COPY rust-toolchain.toml ${PROJECT_DIR}/ +COPY LICENSE ${PROJECT_DIR}/ +COPY README.md ${PROJECT_DIR}/ +COPY src ${PROJECT_DIR}/src/ +COPY tests ${PROJECT_DIR}/tests/ + +ARG BUILD_MODE= + +WORKDIR ${PROJECT_DIR} +RUN cargo build --verbose ${BUILD_MODE} +RUN cargo test --verbose ${BUILD_MODE} -- --nocapture