Skip to content

Commit

Permalink
Add support for static compilation and add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmmm committed Feb 10, 2025
1 parent f07976f commit 84bcf02
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 37 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ jobs:
steps:
- name: Install packages
run: sudo apt install -y --no-install-recommends zlib1g-dev pkg-config libgmp-dev curl ninja-build
- name: Check out repository code
uses: actions/checkout@HEAD
with:
submodules: true
- name: Ensure pre-commit checks pass
run: python3 -m pip install pre-commit && pre-commit run --all-files --show-diff-on-failure --color=always

- name: Install sail from binary
run: |
sudo mkdir -p /usr/local
curl --location https://github.com/rems-project/sail/releases/download/0.18-linux-binary/sail.tar.gz | sudo tar xvz --directory=/usr/local --strip-components=1
- name: Check out repository code
uses: actions/checkout@v4

- name: Ensure pre-commit checks pass
run: python3 -m pip install pre-commit && pre-commit run --all-files --show-diff-on-failure --color=always

- name: Build and test simulators
run: |
# Ninja is used because the CMake Makefile generator doesn't
Expand All @@ -29,13 +31,15 @@ jobs:
ninja -C build all riscv_sim_rv32d_rvfi generated_smt_rv64f generated_docs_rv64d
# These targets do not work with Sail 0.18: generated_rmem_rv32d_rmem generated_coq_rv64f_coq
ctest --test-dir build --output-junit tests.xml
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: tests.xml
path: build/tests.xml
if-no-files-found: error

- name: Upload event payload
if: always()
uses: actions/upload-artifact@v4
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/generate-json.yml

This file was deleted.

104 changes: 104 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release, e.g. 1.0.0'
required: true
notes:
description: 'Release notes'
required: false
prerelease:
description: 'Is this a pre-release (beta, RC, etc.)?'
required: false
type: boolean
draft:
description: 'Is this a draft release (not public; you can publish it later)?'
required: false
type: boolean

jobs:
build:
strategy:
matrix:
include:
- name: linux-amd64
os: ubuntu-latest
container: rockylinux:8.9.20231119

# TODO: Mac. We need a Mac binary release of the Sail compiler first.
# - name: mac-arm64
# os: macos-latest
# container: ""

runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}

steps:
# This must be before checkout otherwise Github will use a zip of the
# code instead of git clone.
- name: Install dependencies (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
dnf update -y --enablerepo=devel
dnf install -y --enablerepo=devel \
pkg-config \
gmp-static \
zlib-static \
curl \
git \
make \
gcc \
gcc-c++ \
cmake \
ninja-build
curl --location --output sail.tar.gz https://github.com/rems-project/sail/releases/download/0.18-linux-binary/sail.tar.gz
tar --directory=/usr/local --strip-components=1 --extract --file sail.tar.gz
# TODO: Mac
# - name: Install dependencies (Mac)
# if: startsWith(matrix.os, 'macos')
# run: |
# brew install --force --overwrite ...

- uses: actions/checkout@v4

- name: Build simulators and JSON
run: |
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Release -DSTATIC=TRUE
cd build
ninja all generated_docs_rv64d
ctest
cpack
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.name }}
path: |
build/sail_riscv-*
build/model/riscv_model_rv64d.json
if-no-files-found: error

release:
needs: build
runs-on: ubuntu-latest
permissions:
# Required to create a release.
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Create release
uses: softprops/action-gh-release@v2
with:
# TODO: When multiple platforms are supported add `release-linux-amd64/` prefix.
files: |
release-linux-amd64/sail_riscv-Linux-x86_64.tar.gz
release-linux-amd64/model/riscv_model_rv64d.json
fail_on_unmatched_files: true
tag_name: ${{ inputs.version }}
body: ${{ inputs.notes }}
prerelease: ${{ inputs.prerelease }}
draft: ${{ inputs.draft }}
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ endif()
# Extra CMake files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# This will change how the `find_library` calls work so they find
# the static version of libraries first. Unlike `-static` it won't
# link glibc statically, which is generally considered to be a bad idea.
option(STATIC "Prefer static versions of dependencies.")

if (STATIC)
if (WIN32)
list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
endif()


# These are the main requirements.
# Don't use `REQUIRED` so that we can print custom help messages.
find_package(ZLIB)
Expand Down Expand Up @@ -85,6 +99,22 @@ add_subdirectory("c_emulator")
# Old pre-compiled riscv-tests.
add_subdirectory("test/riscv-tests")

# Release packaging.
if (NOT CPACK_GENERATOR)
if (WINDOWS)
set(CPACK_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TGZ")
endif()
endif()
if (DARWIN)
# ${CMAKE_SYSTEM_NAME} is unfortunately "Darwin", but we want "Mac".
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-Mac-${CMAKE_HOST_SYSTEM_PROCESSOR}")
else()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
include(CPack)

# Convenience targets.
add_custom_target(csim DEPENDS riscv_sim_rv32d riscv_sim_rv64d)
add_custom_target(check DEPENDS generated_model_rv32d generated_model_rv64d)
Expand Down
5 changes: 4 additions & 1 deletion c_emulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ foreach (xlen IN ITEMS 32 64)
# -Wno-unused-parameter
# )

install(TARGETS riscv_sim_${arch} OPTIONAL)
install(TARGETS riscv_sim_${arch}
OPTIONAL
RUNTIME DESTINATION "bin"
)
endforeach()
endforeach()
endforeach()

0 comments on commit 84bcf02

Please sign in to comment.