Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7838213
update some third party libraries
phlptp Mar 16, 2026
9114ab0
add code to generate a units module from the c++ library
phlptp Mar 27, 2026
b259064
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
5120bcf
move the package install tests out of circle ci
phlptp Mar 27, 2026
11b702c
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 27, 2026
865b0b1
update the tests
phlptp Mar 27, 2026
e4dea94
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
1f066bf
gate out one of the tests
phlptp Mar 27, 2026
88460ba
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 27, 2026
728f2c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
b7687f1
update the module package tests to use a consistent cxx standard
phlptp Mar 27, 2026
a707390
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 27, 2026
dc77e58
update cmake code for generating modules
phlptp Mar 27, 2026
1c3c93d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
961d3c0
update the imported tests
phlptp Mar 27, 2026
31515e6
add the exported interface
phlptp Mar 27, 2026
60023e9
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 27, 2026
44b3e5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
48e1193
try different variation of the module build
phlptp Mar 27, 2026
e5f2e12
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 27, 2026
7e6beb2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2026
84287c1
use module to define variables as inline constexpr
phlptp Mar 28, 2026
ec16ffc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
59c890a
move most constexpr variables to use inline form
phlptp Mar 28, 2026
eeada64
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
8861a07
update workflow to use clang instead of gcc
phlptp Mar 28, 2026
9d8a0ea
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 28, 2026
5b6563a
update styles
phlptp Mar 28, 2026
1040eb2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
359372f
remove the namespaces from the module definition
phlptp Mar 28, 2026
15f7f97
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 28, 2026
e7d4af9
add the correct flags to the build for char8_t
phlptp Mar 28, 2026
2e7d88b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
a76a9ee
forward more build parameters so things match
phlptp Mar 28, 2026
9e0eb74
Merge branch 'units_module' of https://github.com/LLNL/units into uni…
phlptp Mar 28, 2026
617be61
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
f4c17eb
update c++ standard requirements
phlptp Mar 28, 2026
0874d21
add some more units to the export surface
phlptp Mar 28, 2026
f0e5f68
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
version: 2
aliases:
- &setup_units
name: setup_units
environment:
command: |
mkdir -p build
cd build
eval cmake .. ${CMAKE_FLAGS}
make -j 4

- &run_units
name: run_units
environment:
Expand All @@ -29,13 +20,6 @@ aliases:
make -j 4
make QUICK_RAW_FUZZ

- &run_installer_tests
name: run_installer_tests
command: |
cd build
make install
ctest -V -R find-package-tests

jobs:
unitsTSan:
machine:
Expand Down Expand Up @@ -92,33 +76,11 @@ jobs:
- store_artifacts:
path: /root/project/build/FuzzTargets/units_fail_measurement_artifact.txt

unitsInstall:
docker:
- image: helics/buildenv:builder
environment:
CMAKE_FLAGS: "-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON"
steps:
- checkout
- run: *setup_units
- run: *run_installer_tests

unitsInstall-alt:
docker:
- image: helics/buildenv:builder
environment:
CMAKE_FLAGS: "-DUNITS_ENABLE_TESTS=ON -DUNITS_INSTALL_PACKAGE_TESTS=ON -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS"
steps:
- checkout
- run: *setup_units
- run: *run_installer_tests

workflows:
version: 2
units_test:
jobs:
# - unitsMSan
- unitsASan
# - unitsTSan
- unitsInstall
- unitsInstall-alt
- unitsFuzz
119 changes: 119 additions & 0 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Packaging Tests
on:
push:
branches:
- main
- v*
pull_request:
branches:
- main

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

permissions:
contents: read

env:
CTEST_OUTPUT_ON_FAILURE: "1"

jobs:
install:
name: Install Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true

- name: Configure
run: |
cmake -S . -B build \
-DUNITS_ENABLE_TESTS=ON \
-DUNITS_INSTALL_PACKAGE_TESTS=ON \
-DUNITS_BUILD_SHARED_LIBRARY=ON \
-DCMAKE_INSTALL_PREFIX=/home/runner/work/install

- name: Build
run: cmake --build build -j2

- name: Install
run: cmake --install build

- name: Run package tests
run: ctest --output-on-failure -R find-package-tests
working-directory: build

install-alt:
name: Install Tests Alt Package Name
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: true

- name: Configure
run: |
cmake -S . -B build \
-DUNITS_ENABLE_TESTS=ON \
-DUNITS_INSTALL_PACKAGE_TESTS=ON \
-DUNITS_BUILD_SHARED_LIBRARY=ON \
-DUNITS_CMAKE_PROJECT_NAME=LLNL-UNITS \
-DCMAKE_INSTALL_PREFIX=/home/runner/work/install

- name: Build
run: cmake --build build -j2

- name: Install
run: cmake --install build

- name: Run package tests
run: ctest --output-on-failure -R find-package-tests
working-directory: build

install-module:
name: Install Module Tests
runs-on: ubuntu-latest
steps:
- name: Set up Clang
uses: egor-tensin/setup-clang@v2
with:
version: 20
platform: x64
- name: Install specific libc++ version
run: |
sudo apt-get update
sudo apt-get install -y libc++-20-dev libc++abi-20-dev lld-20
- uses: actions/checkout@v6
with:
submodules: true

- uses: ./.github/actions/quick_cmake
with:
cmake-version: "4.2"

- uses: seanmiddleditch/gha-setup-ninja@master

- name: Configure
run: |
cmake -S . -B build -G Ninja \
-DUNITS_ENABLE_TESTS=ON \
-DUNITS_INSTALL_PACKAGE_TESTS=ON \
-DUNITS_BUILD_SHARED_LIBRARY=ON \
-DUNITS_BUILD_CXX_MODULE=ON \
-DCMAKE_CXX_STANDARD=23 \
-DCMAKE_INSTALL_PREFIX=/home/runner/work/install \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_LINKER_TYPE=LLD \
-DCMAKE_CXX_FLAGS=-stdlib=libc++

- name: Build
run: cmake --build build -j2

- name: Install
run: cmake --install build

- name: Run package tests
run: ctest --output-on-failure -R find-package-tests
working-directory: build
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ cmake_dependent_option(
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF
)

cmake_dependent_option(
UNITS_BUILD_CXX_MODULE "Build an experimental C++20 module wrapper target" OFF
"NOT CMAKE_VERSION VERSION_LESS 3.28;NOT UNITS_HEADER_ONLY" OFF
)

cmake_dependent_option(
UNITS_PYTHON_ONLY_INSTALL "Only install the python library" SKBUILD
"UNITS_BUILD_PYTHON_LIBRARY" OFF
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ The second part is a few cpp files that can add some additional functionality. T

It builds by default with the static library. Using `UNIT_BUILD_SHARED_LIBRARY` or `BUILD_SHARED_LIBS` will build the shared library instead. Either one can be used with CMake as a `units::units` target. The header only library target is also generated `units::header_only`. The shared/static library has a CMake target `units::units`.

An experimental C++20 module wrapper can also be enabled with `-DUNITS_BUILD_CXX_MODULE=ON` when configuring with CMake 3.28 or newer. This adds a `units::module` target that exports the module name `units` from `units/units.cppm`.

```cmake
target_link_libraries(my_app PRIVATE units::module)
target_compile_features(my_app PRIVATE cxx_std_20)
```

```cpp
import units;

int main()
{
auto speed = 12.0 * units::m / units::s;
return (speed.units() == units::m / units::s) ? 0 : 1;
}
```

The module currently guarantees a curated public surface in the `units::` namespace, including:

- Core types and functions such as `unit`, `precise_unit`, `measurement`, `precise_measurement`, `convert`, `quick_convert`, `unit_from_string`, `measurement_from_string`, and `to_string`
- All seven SI base units by symbol or common name: `m`/`meter`, `kg`/`kilogram`, `s`/`second`, `A`/`Ampere`, `K`/`Kelvin`, `mol`, and `cd`
- Common SI and SI-derived units: `rad`, `Hz`, `N`, `J`, `W`, `V`, `ohm`, `Pa`, `C`, `cm`, `mm`, `km`, `L`, `g`, `degC`, and `degF`
- Common non-SI and scalar units: `minute`, `h`, `hr`, `ft`/`foot`, `in`/`inch`, `mile`, `lb`, `gal`, `deg`, `mph`, `count`, and `currency`
- Main prefixes as scalar units: `milli`, `micro`, `nano`, `pico`, `kilo`, `mega`, and `giga`

Additional units remain available through the traditional headers, especially in `units::precise` and its subnamespaces.

## Try it out

If you want to try out the string conversion components. There is server running that can do the string conversions
Expand Down
Loading
Loading