Skip to content

Commit

Permalink
Merge pull request #421 from cse-sim/build-tree
Browse files Browse the repository at this point in the history
Generalize build tree to support additional platforms/compilers/architectures
  • Loading branch information
nealkruis authored Mar 25, 2024
2 parents 73c9d9e + dbe3cb0 commit 829745e
Show file tree
Hide file tree
Showing 77 changed files with 234 additions and 70 deletions.
23 changes: 20 additions & 3 deletions .github/actions/build-cse/action.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
name: "Build CSE"
description: "Get git info (for version) and build CSE executable"
inputs:
arch:
description: Target architecture ("32" or "64" bit)
default: "32"
config:
description: Configuration (Release or Debug)
default: Release
compiler:
description: Compiler used for windows builds (clang or msvc)
default: msvc
build_dir:
description: Relative path to the build directory
default: build
runs:
using: composite
steps:
- name: Get branch name
uses: tj-actions/[email protected]
id: branch-name
- name: Install Linux Libraries
if: runner.os == 'Linux'
shell: bash
run: sudo apt-get update && sudo apt-get -y install xorg-dev libgl1-mesa-dev
- name: Save branch name
run: echo "CI_GIT_BRANCH=${{steps.branch-name.outputs.current_branch}}" >> $GITHUB_ENV
shell: bash
- name: Build
shell: cmd
run: build.bat
- name: Build and Configure
shell: bash
run: cmake -DBUILD_ARCHITECTURE=${{ inputs.arch }} -DCOMPILER_ID=${{ inputs.compiler }} -DCONFIGURATION=${{ inputs.config }} -DTARGET_NAME=CSE -DBUILD_DIRECTORY=${{ inputs.build_dir }} -P cmake/configure-and-build.cmake
3 changes: 3 additions & 0 deletions .github/actions/build-docs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ runs:
run: rake
shell: bash
working-directory: doc
env:
CSE_EXE_PATH: ..\\build\\CSE.exe

4 changes: 2 additions & 2 deletions .github/actions/download-cse-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ runs:
- name: Download executable artifact
uses: actions/download-artifact@v4
with:
name: CSE.exe
path: msvc
name: CSE_windows-2022-32bit_Release
path: build
64 changes: 53 additions & 11 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,46 @@ on: push

jobs:
build-cse:
name: Build and test CSE
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
include:
- os: windows
os_ver: "2022"
config: Release
arch: "32"
compiler: msvc
experimental: false
- os: windows
os_ver: "2022"
config: Release
arch: "64"
compiler: msvc
experimental: true
- os: windows
os_ver: "2022"
config: Release
arch: "64"
compiler: clang
experimental: true
- os: macos
os_ver: "11"
config: Release
arch: "64"
compiler: clang
experimental: true
- os: ubuntu
os_ver: "22.04"
config: Release
arch: "64"
compiler: gcc
experimental: true
defaults:
run:
shell: bash
name: ${{ matrix.os }}-${{ matrix.os_ver }}-${{ matrix.compiler }}-${{ matrix.arch }}bit ${{ matrix.config }}
runs-on: ${{ matrix.os }}-${{ matrix.os_ver }}
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -17,27 +52,32 @@ jobs:
submodules: recursive
- name: Build CSE
uses: ./.github/actions/build-cse
with:
arch: ${{ matrix.arch }}
config: ${{ matrix.config }}
compiler: ${{ matrix.compiler }}
- name: Build cse_tests.exe (unit tests)
run: cmake --build . --config Release --target cse_tests
working-directory: msvc/build
- name: Upload cse.exe artifact
run: cmake -DBUILD_ARCHITECTURE=${{ matrix.arch }} -DCONFIGURATION=${{ matrix.config }} -DTARGET_NAME=cse_tests -DBUILD_DIRECTORY=build -P cmake/build.cmake
- name: Upload executable artifact
uses: actions/upload-artifact@v4
with:
name: CSE.exe
path: msvc/CSE.exe
name: CSE_${{ matrix.os }}-${{ matrix.os_ver }}-${{ matrix.arch }}bit_${{ matrix.config }}
path: build/CSE*
- name: Build wcmp executable
run: cmake --build . --config Release --target wcmp
working-directory: msvc/build
run: cmake -DBUILD_ARCHITECTURE=${{ matrix.arch }} -DCONFIGURATION=${{ matrix.config }} -DTARGET_NAME=wcmp -DBUILD_DIRECTORY=build -P cmake/build.cmake
# - name: Setup Mesa3D
# uses: bigladder/github-actions/setup-mesa3d@main
# with:
# install-directory: msvc
- name: Test
run: ctest -C Release -j 2 --output-on-failure -E shadetest # CI can't do GPU calcs at this time (the steps above get us close, but throws an exception on destruction)
working-directory: msvc/build
run: ctest -C ${{ matrix.config }} -j 2 --output-on-failure -E shadetest # CI can't do GPU calcs at this time (the steps above get us close, but throws an exception on destruction)
working-directory: build
build-doc:
strategy:
fail-fast: false
name: Build CSE documentation
needs: build-cse
if: ${{ always() }}
runs-on: windows-2022
steps:
- name: Checkout
Expand All @@ -51,6 +91,8 @@ jobs:
- name: Run coverage check
run: rake coverage
working-directory: doc
env:
CSE_EXE_PATH: ..\\build\\CSE.exe
- name: Upload documentation
uses: actions/upload-artifact@v4
with:
Expand Down
23 changes: 21 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(CSE)
# target_link_libraries() allows use with targets in other directories. Set to new in 3.13 or higher.
cmake_policy(SET CMP0079 NEW)

set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Only create Release and Debug configuration types
# Set a default build type if none was specified
Expand All @@ -32,12 +32,31 @@ if(NOT CSE_BUILD_ARCHITECTURE)
set_property(CACHE CSE_BUILD_ARCHITECTURE PROPERTY STRINGS "32" "64")
else()
if(NOT WIN32 AND CSE_BUILD_ARCHITECTURE STREQUAL "32")
# TODO: Warn if 32 used on MacOS or Linux and set to 64
message(WARNING "CSE_BUILD_ARCHITECTURE was set to '32', but is not supported on Unix systems.")
set(CSE_BUILD_ARCHITECTURE "64" CACHE STRING "Choose architecture size for the build." FORCE)
endif()
endif()

# Build OS
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(CSE_OS_NAME "macos")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(CSE_OS_NAME "win")
else()
string(TOLOWER ${CMAKE_SYSTEM_NAME} CSE_OS_NAME)
endif()

# Build Compiler
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(CSE_COMPILER_NAME "gcc")
else()
string(TOLOWER ${CMAKE_CXX_COMPILER_ID} CSE_COMPILER_NAME)
endif()

if(NOT DEFINED CSE_EXECUTABLE_DIRECTORY)
set(CSE_EXECUTABLE_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

include(BuildFlags)
Expand Down
10 changes: 4 additions & 6 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ if "%console_mode%"=="" (set console_mode=1& for %%x in (%cmdcmdline%) do if /i
set arch="32"
if "%1"=="64" (set arch="%1")

cmake -DBUILD_ARCHITECTURE=%arch% -P cmake/configure.cmake
if %errorlevel% neq 0 (
if "%parent%"=="%~0" ( if "%console_mode%"=="0" pause )
exit /B %errorlevel%
)
set compiler="msvc"
if "%2"=="clang" (set compiler="clang")


cmake -DBUILD_ARCHITECTURE=%arch% -P cmake/build.cmake
cmake -DBUILD_ARCHITECTURE=%arch% -DCONFIGURATION=Release -DCOMPILER_ID=%compiler% -P cmake/configure-and-build.cmake
if %errorlevel% neq 0 (
if "%parent%"=="%~0" ( if "%console_mode%"=="0" pause )
exit /B %errorlevel%
Expand Down
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

cmake -DCONFIGURATION=Release -P cmake/configure-and-build.cmake
30 changes: 20 additions & 10 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
message("Building CSE...")
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/msvc/build)
if ("${BUILD_ARCHITECTURE}" STREQUAL "64")
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/msvc/build64)
endif()
if (NOT DEFINED TARGET_NAME)
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(TARGET_NAME "ALL_BUILD") # Needed for MSVC (not necessarily all Windows builds)
else ()
set(TARGET_NAME "all")
endif ()
endif ()
message("Building ${TARGET_NAME}...")

include(cmake/utility.cmake)
set_build_configuration()
if (NOT DEFINED BUILD_DIRECTORY)
set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builds/${BUILD_CONFIGURATION}")
endif ()

execute_process(COMMAND ${CMAKE_COMMAND}
--build ${BUILD_DIR}
--config Release
--target CSE
-- -m
WORKING_DIRECTORY ${BUILD_DIR}
--build .
--config ${CONFIGURATION}
--target ${TARGET_NAME}
-j
WORKING_DIRECTORY ${BUILD_DIRECTORY}
RESULT_VARIABLE success
)
if (${success} MATCHES "0")
Expand Down
2 changes: 2 additions & 0 deletions cmake/configure-and-build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include(cmake/configure.cmake)
include(cmake/build.cmake)
40 changes: 29 additions & 11 deletions cmake/configure.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
set(TARGET_VS_ARCHITECTURE Win32)
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/msvc/build)
if ("${BUILD_ARCHITECTURE}" STREQUAL "64")
set(TARGET_VS_ARCHITECTURE x64)
set(BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/msvc/build64)
include(cmake/utility.cmake)
set_build_configuration()
if (NOT DEFINED BUILD_DIRECTORY)
set(BUILDS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/builds")
set(BUILD_DIRECTORY "${BUILDS_DIRECTORY}/${BUILD_CONFIGURATION}")
set(EXECUTABLE_DIRECTORY ${BUILDS_DIRECTORY})
endif ()

file(MAKE_DIRECTORY ${BUILD_DIRECTORY})

set(configure_command ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR} -DCSE_BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE})

if (DEFINED EXECUTABLE_DIRECTORY)
set(configure_command ${configure_command} -DCSE_EXECUTABLE_DIRECTORY=${EXECUTABLE_DIRECTORY})
endif ()

if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
if (${COMPILER_ID} STREQUAL "msvc")
set(configure_command ${configure_command} -T v142,version=14.29.16.11 -A ${TARGET_VS_ARCHITECTURE} -DCMAKE_SYSTEM_VERSION=10.0.20348.0)
elseif(${COMPILER_ID} STREQUAL "clang")
set(configure_command ${configure_command} -T ClangCL -A ${TARGET_VS_ARCHITECTURE})
endif ()
else()
set(configure_command ${configure_command} -DCMAKE_BUILD_TYPE=${CONFIGURATION})
endif()
message("Making build directory: ${BUILD_DIR}")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/msvc)
file(MAKE_DIRECTORY ${BUILD_DIR})

message("Generating project files...")
execute_process(COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR} -T v142,version=14.29.16.11 -A ${TARGET_VS_ARCHITECTURE} -DCSE_BUILD_ARCHITECTURE=${BUILD_ARCHITECTURE} -DCMAKE_SYSTEM_VERSION=10.0.20348.0
WORKING_DIRECTORY ${BUILD_DIR}
RESULT_VARIABLE success
execute_process(COMMAND ${configure_command}
WORKING_DIRECTORY ${BUILD_DIRECTORY}
RESULT_VARIABLE success
)

if (NOT ${success} MATCHES "0")
message(FATAL_ERROR "Generation step failed.")
endif()
2 changes: 1 addition & 1 deletion cmake/diff-failed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(EXISTS ${testLog})
string(REGEX REPLACE "[0-9]+:([^;].*).Regression" "\\1" test_name "${test}")
string(TOUPPER ${test_name} test_name)
message("Diffing: ${test_name}.REP")
execute_process(COMMAND bc4.bat "${test_name}.REP" "ref/${test_name}.REP"
execute_process(COMMAND bc4.bat "${test_name}.REP" "${ref_dir}/${test_name}.REP"
WORKING_DIRECTORY ${test_dir}
RESULT_VARIABLE success
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/update-failed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if(EXISTS ${testLog})
string(REGEX REPLACE "[0-9]+:([^;].*).Regression" "\\1" test_name "${test}")
string(TOUPPER ${test_name} test_name)
message("Updating: ${test_name}.REP")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${test_name}.REP" "ref/${test_name}.REP"
execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${test_name}.REP" "${ref_dir}/${test_name}.REP"
WORKING_DIRECTORY ${test_dir}
RESULT_VARIABLE success
)
Expand Down
32 changes: 32 additions & 0 deletions cmake/utility.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
macro(set_build_configuration)
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
set(OS_ID "win")
if (NOT DEFINED COMPILER_ID)
set(COMPILER_ID "msvc")
endif ()
if (NOT DEFINED BUILD_ARCHITECTURE)
set(BUILD_ARCHITECTURE "32")
endif ()
if ("${BUILD_ARCHITECTURE}" STREQUAL "64")
set(TARGET_VS_ARCHITECTURE "x64")
else ()
set(TARGET_VS_ARCHITECTURE "Win32")
endif ()
else ()
if (NOT DEFINED CONFIGURATION)
set(CONFIGURATION Release)
endif ()
string(TOLOWER "-${CONFIGURATION}" CONFIGURATION_STRING)
if (NOT DEFINED BUILD_ARCHITECTURE)
set(BUILD_ARCHITECTURE "64")
endif ()
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
set(OS_ID "macos")
set(COMPILER_ID "appleclang")
elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
set(OS_ID "linux")
set(COMPILER_ID "gcc")
endif ()
endif ()
set(BUILD_CONFIGURATION "${OS_ID}${BUILD_ARCHITECTURE}-${COMPILER_ID}${CONFIGURATION_STRING}")
endmacro()
4 changes: 3 additions & 1 deletion doc/lib/cse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ module CSE
# Create an Alias
C = Command

cse_path = ENV.has_key?('CSE_EXE_PATH') ? ENV['CSE_EXE_PATH'] : '..\\builds\\cse'

# (Or (Array String) String) ?String -> String
# Given an array of strings of options to cse and an optional input to
Run = lambda do |opts, input=nil|
C::Run['..\\msvc\\cse', opts, input]
C::Run[cse_path, opts, input]
end

CullList = lambda do
Expand Down
Loading

0 comments on commit 829745e

Please sign in to comment.