Skip to content

Commit

Permalink
Add initial implementation (#2)
Browse files Browse the repository at this point in the history
* Add clang-format and gitignore

* Move celeritas load to a subdirectory

* Set up default celeritas options

* Add implementation

* Add targets for unit test debugging

* Implement test

* Add CI

* Use incoming celeritas PR

* Fix GHA branch target

* Update celeritas URL
  • Loading branch information
sethrj authored Feb 12, 2024
1 parent 2ec1e2f commit e034ada
Show file tree
Hide file tree
Showing 18 changed files with 1,585 additions and 10 deletions.
161 changes: 161 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 79
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
# Category 0: main include
# Category 1: system includes
# Category 2: celeritas absolute includes
# Category 5: relative includes
# Category 7: test includes
IncludeCategories:
- Regex: '^<[^/.]+>$'
Priority: 1
SortPriority: 1
- Regex: '^<.+>$'
Priority: 1
SortPriority: 2
- Regex: '^"celeritas_[a-z_]+\.h"'
Priority: 2
SortPriority: 3
- Regex: '^"corecel/device_runtime_api\.h"$'
Priority: 2
SortPriority: 3
- Regex: '^"corecel/'
Priority: 2
SortPriority: 5
CaseSensitive: true
- Regex: '^"orange/'
Priority: 2
SortPriority: 6
CaseSensitive: true
- Regex: '^"celeritas/'
Priority: 2
SortPriority: 7
CaseSensitive: true
- Regex: '^"accel/'
Priority: 2
SortPriority: 8
CaseSensitive: true
- Regex: '^"[^/]+"'
Priority: 5
SortPriority: 9
- Regex: '^"detail/"'
Priority: 5
SortPriority: 10
- Regex: '"(^gtest/|TestBase|\.test\.hh|celeritas_test\.hh)'
Priority: 7
CaseSensitive: true
SortPriority: 11
- Regex: '.*'
Priority: 5
SortPriority: 9
IncludeIsMainRegex: '(\.[^.]+)?$'
IncludeIsMainSourceRegex: '(\.cu|\.t\.hh)$' # Allow CU/template files as main
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 20
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 1
PenaltyBreakString: 25
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 25
PenaltyReturnTypeOnItsOwnLine: 10
PointerAlignment: Left
QualifierAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
# vim: set ft=yaml ts=2 sw=2 :
65 changes: 65 additions & 0 deletions .github/workflows/build-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: build-full
on:
workflow_dispatch:
workflow_call:

concurrency:
group: build-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}-${{github.workflow}}
cancel-in-progress: true

jobs:
# TODO: this currently includes non-GPU builds as well
# and won't actually run on device
gpu:
name: gpu
strategy:
fail-fast: false
matrix:
special: [null]
geometry: ['vecgeom']
buildtype: ['debug', 'ndebug']
image: ['ubuntu-cuda']
env:
CELER_DISABLE_DEVICE: 1 # IMPORTANT
CMAKE_PRESET: >-
${{matrix.buildtype}}-${{matrix.geometry}}${{matrix.special && '-' || ''}}${{matrix.special}}
runs-on: ubuntu-latest
container:
image: >-
docker.io/celeritas/${{
matrix.image == 'ubuntu-cuda' && 'ci-jammy-cuda11:2023-08-02'
|| null
}}
# See https://github.com/actions/checkout/issues/956
options: --user root
steps:
- name: Set up environment
run: |
. /etc/profile
echo "/opt/view/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
# NOTE: checkout must occur *after* setting up environment for git tags to work
# NOTE: checkout v4 fails: https://github.com/actions/checkout/issues/1487
# NOTE: depth must be enough to include the previous tag
- name: Check out
uses: actions/checkout@v3
- name: Configure
run: |
git config --global --add safe.directory ${PWD}
ln -fs scripts/cmake-presets/ci-${{matrix.image}}.json CMakeUserPresets.json
cmake --preset=${CMAKE_PRESET}
- name: Build
working-directory: build
run: |
ninja
- name: Test
working-directory: build
run: |
ctest --parallel 2 --timeout 180 --output-on-failure \
--test-output-size-passed=65536 --test-output-size-failed=1048576
- name: Install
working-directory: build
run: |
cmake --install .
# vim: set nowrap tw=100:
35 changes: 35 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: pr
run-name: >-
${{github.event.pull_request.title}}
(#${{github.event.number}})
on:
pull_request:
branches:
- main
paths-ignore:
- '**.rst'
- '**.md'
- 'scripts/dev'

concurrency:
group: pr-${{github.ref}}-${{github.event.number}}-${{github.workflow}}
cancel-in-progress: true

jobs:
build:
uses: ./.github/workflows/build-full.yml

# Specifying a dependent job allows us to select a single "requires" check in the project GitHub settings
all:
if: ${{ always() }}
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}

# vim: set nowrap tw=100:
27 changes: 27 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: push
# TODO: improve run name using commit title (`message` includes details as well)
# run-name: >-
# ${{github.ref_name}}:
# ${{github.event.head_commit.message}}
# (${{github.event.pusher.name}})

on:
push:
branches:
- main

concurrency:
group: push-${{github.ref}}-${{github.run_number}}-${{github.workflow}}
cancel-in-progress: true

jobs:
build-full:
uses: ./.github/workflows/build-full.yml
all:
needs: [build-full]
runs-on: ubuntu-latest
steps:
- name: Success
run: "true"

# vim: set nowrap tw=100:
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@
*.exe
*.out
*.app

# Misc
*.cache
*.pyc
*.swp
*~
.DS_Store
.nfs*
.vscode
/build*
/install*
/spack-build*
/CMakeUserPresets.json
Testing
compile_commands.json
cmake_install.cmake
/CMakeCache.txt
/CMakeFiles
71 changes: 61 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,66 @@
cmake_minimum_required(VERSION 3.14...3.28)
project(G4VG VERSION 0.1.0 LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(
celeritas
# Current tip of celeritas develop - adjust as needed
URL https://github.com/celeritas-project/celeritas/archive/5742b0c924a67bf02ec0ce9fc85719a70f7857e0.zip
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

#----------------------------------------------------------------------------#
# Utilities

include(GNUInstallDirs)

macro(g4vg_set_default name value)
if(NOT DEFINED ${name})
message(VERBOSE "G4VG: set default ${name}=${value}")
set(${name} "${value}")
endif()
endmacro()

# Set/force any Celeritas CMake args here before making it available, e.g.
set(CELERITAS_USE_MPI OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(celeritas)
#----------------------------------------------------------------------------#
# Options

option(G4VG_BUILD_TESTS "Build G4VG unit tests" OFF)
g4vg_set_default(BUILD_TESTING ${G4VG_BUILD_TESTS})

g4vg_set_default(CMAKE_CXX_EXTENSIONS OFF)

#----------------------------------------------------------------------------#
# Add code

# Use any celeritas targets as normal (or CMake modules)
add_subdirectory(external)
add_subdirectory(src)

#----------------------------------------------------------------------------#
# Add tests

if(BUILD_TESTING)
include(CTest)
endif()
if(G4VG_BUILD_TESTS)
if(NOT GTest_FOUND)
find_package(GTest 1.10 REQUIRED)
endif()
if(NOT VecGeom_FOUND)
# Note: using the same version as celeritas to silence cmake config
# messages
find_package(VecGeom 1.2.4 REQUIRED)
endif()
if(NOT Geant4_FOUND)
find_package(Geant4 REQUIRED)
endif()

add_subdirectory(test)
endif()

#----------------------------------------------------------------------------#
# Export CMake for installation downstream

set(G4VG_INSTALL_CMAKECONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/G4VG")

# Install 'G4VGTargets.cmake', included by G4VGConfig.cmake, which
# references the targets we install.
install(EXPORT g4vg-targets
FILE G4VGTargets.cmake
NAMESPACE G4VG::
DESTINATION "${G4VG_INSTALL_CMAKECONFIGDIR}"
COMPONENT development
)
Loading

0 comments on commit e034ada

Please sign in to comment.