From 7de4c2f5353c33eee3eb1359a4706f765c1c0af0 Mon Sep 17 00:00:00 2001 From: Alex Denisov Date: Sat, 30 Nov 2024 10:44:03 +0100 Subject: [PATCH 1/3] Add devcontainer --- .devcontainer/Dockerfile | 24 +++++++++++++ .devcontainer/devcontainer.json | 7 ++++ .devcontainer/post_create.sh | 4 +++ .devcontainer/reinstall-cmake.sh | 59 ++++++++++++++++++++++++++++++++ .github/workflows/linux-ci.yml | 22 ++++++++++++ .github/workflows/macos-ci.yml | 2 +- .gitignore | 2 ++ CMakePresets.json | 19 ++++++++++ cmake/mruby.cmake | 6 ++-- lib/conversion/c_conversion.cpp | 3 +- lib/runtime/CMakeLists.txt | 1 + tests/benchmarks/CMakeLists.txt | 2 +- 12 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/post_create.sh create mode 100644 .devcontainer/reinstall-cmake.sh create mode 100644 .github/workflows/linux-ci.yml create mode 100644 CMakePresets.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b2ffeb8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 + +ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.29.3" + +COPY ./reinstall-cmake.sh /tmp/ + +RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ + chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ + fi \ + && rm -f /tmp/reinstall-cmake.sh + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + software-properties-common fish + +RUN add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" +RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + clang-19 clang++-19 llvm-19-dev libmlir-19-dev mlir-19-tools \ + rake python3-pip libzstd-dev + +RUN pip install lit filecheck==0.0.24 pre-commit --break-system-packages diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..1a11b3b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,7 @@ +{ + "name": "Lightstorm", + "build": { + "dockerfile": "Dockerfile" + }, + "postCreateCommand": "sh .devcontainer/post_create.sh" +} diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh new file mode 100644 index 0000000..6e157a8 --- /dev/null +++ b/.devcontainer/post_create.sh @@ -0,0 +1,4 @@ +set -e + +pre-commit install +git submodule update --init --recursive diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh new file mode 100644 index 0000000..408b81d --- /dev/null +++ b/.devcontainer/reinstall-cmake.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +set -e + +CMAKE_VERSION=${1:-"none"} + +if [ "${CMAKE_VERSION}" = "none" ]; then + echo "No CMake version specified, skipping CMake reinstallation" + exit 0 +fi + +# Cleanup temporary directory and associated files when exiting the script. +cleanup() { + EXIT_CODE=$? + set +e + if [[ -n "${TMP_DIR}" ]]; then + echo "Executing cleanup of tmp files" + rm -Rf "${TMP_DIR}" + fi + exit $EXIT_CODE +} +trap cleanup EXIT + + +echo "Installing CMake..." +apt-get -y purge --auto-remove cmake +mkdir -p /opt/cmake + +architecture=$(dpkg --print-architecture) +case "${architecture}" in + arm64) + ARCH=aarch64 ;; + amd64) + ARCH=x86_64 ;; + *) + echo "Unsupported architecture ${architecture}." + exit 1 + ;; +esac + +CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" +CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" +TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) + +echo "${TMP_DIR}" +cd "${TMP_DIR}" + +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O +curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O + +sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" +sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license + +ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake +ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml new file mode 100644 index 0000000..dce2b5c --- /dev/null +++ b/.github/workflows/linux-ci.yml @@ -0,0 +1,22 @@ +name: Linux CI +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: devcontainers/ci@v0.3 + with: + imageName: ghcr.io/dragonruby/internal-lightstorm-ci + runCmd: | + cmake --preset lightstorm + cmake --build ./build.debug.dir/build -t run-integration-tests diff --git a/.github/workflows/macos-ci.yml b/.github/workflows/macos-ci.yml index dcbf795..7c91436 100644 --- a/.github/workflows/macos-ci.yml +++ b/.github/workflows/macos-ci.yml @@ -5,7 +5,7 @@ on: pull_request: branches: ["main"] jobs: - build: + build-and-test: runs-on: ${{ matrix.os }} strategy: fail-fast: false diff --git a/.gitignore b/.gitignore index 83260f8..46f8468 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ Output +build*dir +*.lit_test_times.txt diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..73c8daf --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,19 @@ +{ + "version": 8, + "configurePresets": [ + { + "name": "lightstorm", + "displayName": "lightstorm", + "description": "Sets Ninja generator, build and install directory", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build.debug.dir/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_C_COMPILER": "clang-19", + "CMAKE_CXX_COMPILER": "clang++-19", + "CMAKE_PREFIX_PATH": "/usr/lib/llvm-19/lib/cmake", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/build.debug.dir/install" + } + } + ] +} diff --git a/cmake/mruby.cmake b/cmake/mruby.cmake index 0ca3c9a..a47acda 100644 --- a/cmake/mruby.cmake +++ b/cmake/mruby.cmake @@ -8,8 +8,10 @@ ExternalProject_Add( mruby SOURCE_DIR ${MRUBY_DIR} CONFIGURE_COMMAND "" - BUILD_COMMAND ${CMAKE_COMMAND} -E env CFLAGS="${LIGHTSTORM_CFLAGS}" - LDFLAGS="${LIGHTSTORM_CFLAGS}" rake all --verbose + BUILD_COMMAND + ${CMAKE_COMMAND} -E env CC=${CMAKE_C_COMPILER} CPP=${CMAKE_CXX_COMPILER} + CFLAGS="${LIGHTSTORM_CFLAGS}" LDFLAGS="${LIGHTSTORM_CFLAGS}" rake all + --verbose BUILD_IN_SOURCE ON INSTALL_COMMAND "" BUILD_BYPRODUCTS ${MRUBY_STATIC} ${MRUBY_BINARY} ${MRBC_BINARY} diff --git a/lib/conversion/c_conversion.cpp b/lib/conversion/c_conversion.cpp index ae89158..5c6deff 100644 --- a/lib/conversion/c_conversion.cpp +++ b/lib/conversion/c_conversion.cpp @@ -1,5 +1,6 @@ #include "lightstorm/conversion/conversion.h" #include "lightstorm/dialect/rite.h" +#include #include #include #include @@ -55,7 +56,7 @@ static std::string cCompatibleSymName(const std::string &sym) { std::string s; std::stringstream ss(s); for (auto c : sym) { - if (isalpha(c) || isnumber(c)) { + if (isalpha(c) || isdigit(c)) { ss << c; continue; } diff --git a/lib/runtime/CMakeLists.txt b/lib/runtime/CMakeLists.txt index 562cbc6..e6de777 100644 --- a/lib/runtime/CMakeLists.txt +++ b/lib/runtime/CMakeLists.txt @@ -6,4 +6,5 @@ target_include_directories( ${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include) target_compile_options(lightstorm_runtime_main PRIVATE ${LIGHTSTORM_CFLAGS}) target_link_options(lightstorm_runtime_main PRIVATE ${LIGHTSTORM_CFLAGS}) +target_link_libraries(lightstorm_runtime_main PUBLIC m) add_dependencies(lightstorm_runtime_main mruby_static) diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index 1bd4982..1bb5fb4 100644 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -13,7 +13,7 @@ function(add_bench_executable ruby) PRIVATE ${CMAKE_SOURCE_DIR}/third_party/mruby/include ${CMAKE_SOURCE_DIR}/third_party/mruby/build/host/include) target_compile_options(${target_name} PRIVATE -g) - target_link_libraries(${target_name} PRIVATE mruby_static) + target_link_libraries(${target_name} PRIVATE mruby_static m) add_dependencies(${target_name} mruby_static) endfunction() From c611470f896302b7c1ad88db51c02e19a6bb5b0c Mon Sep 17 00:00:00 2001 From: Alex Denisov Date: Sat, 30 Nov 2024 12:32:20 +0100 Subject: [PATCH 2/3] Use https for submodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 03be569..244af92 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "third_party/mruby"] path = third_party/mruby - url = git@github.com:mruby/mruby.git + url = https://github.com/mruby/mruby.git From a4f8985702a523d7d4af3583ef820c7f84eb92fa Mon Sep 17 00:00:00 2001 From: Alex Denisov Date: Sat, 30 Nov 2024 15:39:01 +0100 Subject: [PATCH 3/3] Switch to external cmake feature --- .devcontainer/Dockerfile | 9 ----- .devcontainer/devcontainer.json | 8 +++++ .devcontainer/reinstall-cmake.sh | 59 -------------------------------- .github/workflows/macos-ci.yml | 6 +--- 4 files changed, 9 insertions(+), 73 deletions(-) delete mode 100644 .devcontainer/reinstall-cmake.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b2ffeb8..6b18af3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,14 +1,5 @@ FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04 -ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.29.3" - -COPY ./reinstall-cmake.sh /tmp/ - -RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ - chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ - fi \ - && rm -f /tmp/reinstall-cmake.sh - RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends \ software-properties-common fish diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1a11b3b..021a703 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,5 +3,13 @@ "build": { "dockerfile": "Dockerfile" }, + "features": { + // Switch to the "official" version as soon as + // https://github.com/devcontainers-community/features-cmake/pull/2 + // merged + "ghcr.io/alexdenisov/features/feature-cmake": { + "version": "3.29.3" + } + }, "postCreateCommand": "sh .devcontainer/post_create.sh" } diff --git a/.devcontainer/reinstall-cmake.sh b/.devcontainer/reinstall-cmake.sh deleted file mode 100644 index 408b81d..0000000 --- a/.devcontainer/reinstall-cmake.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash -#------------------------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. -#------------------------------------------------------------------------------------------------------------- -# -set -e - -CMAKE_VERSION=${1:-"none"} - -if [ "${CMAKE_VERSION}" = "none" ]; then - echo "No CMake version specified, skipping CMake reinstallation" - exit 0 -fi - -# Cleanup temporary directory and associated files when exiting the script. -cleanup() { - EXIT_CODE=$? - set +e - if [[ -n "${TMP_DIR}" ]]; then - echo "Executing cleanup of tmp files" - rm -Rf "${TMP_DIR}" - fi - exit $EXIT_CODE -} -trap cleanup EXIT - - -echo "Installing CMake..." -apt-get -y purge --auto-remove cmake -mkdir -p /opt/cmake - -architecture=$(dpkg --print-architecture) -case "${architecture}" in - arm64) - ARCH=aarch64 ;; - amd64) - ARCH=x86_64 ;; - *) - echo "Unsupported architecture ${architecture}." - exit 1 - ;; -esac - -CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" -CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" -TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) - -echo "${TMP_DIR}" -cd "${TMP_DIR}" - -curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O -curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O - -sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" -sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license - -ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake -ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest diff --git a/.github/workflows/macos-ci.yml b/.github/workflows/macos-ci.yml index 7c91436..88a53f5 100644 --- a/.github/workflows/macos-ci.yml +++ b/.github/workflows/macos-ci.yml @@ -6,11 +6,7 @@ on: branches: ["main"] jobs: build-and-test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-latest] + runs-on: macos-latest steps: - uses: actions/checkout@v4 with: