Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: setup pixi #6

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SCM syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
35 changes: 35 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Coverage

on:
push:
branches:
- main
pull_request:

permissions:
contents: read # to fetch code (actions/checkout)

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
codecov:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.35.0
cache: true

- name: Run tests and generate coverage report
run: pixi run tests-coverage

- name: Upload HTML coverage report
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: cov-html
path: build/coverage_report/**
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/

# Prerequisites
*.d

Expand Down Expand Up @@ -30,3 +32,7 @@
*.exe
*.out
*.app

# pixi environments
.pixi
*.egg-info
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.14)
project(xsf)

# Scipy requ C++17
# https://docs.scipy.org/doc/scipy/dev/toolchain.html#c-language-standards
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(${CMAKE_SOURCE_DIR}/include)

# Tests
enable_testing()
add_subdirectory(tests)
2,930 changes: 2,930 additions & 0 deletions pixi.lock

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[project]
authors = [
"Albert Steppi <[email protected]>",
"Irwin Zaid <[email protected]>",
]
channels = ["conda-forge"]
description = "Special function implementations."
name = "xsf"
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]

## Build

[feature.build.dependencies]
cmake = ">=3.30.5,<4"
cxx-compiler = ">=1.8.0,<2"
make = ">=4.4.1,<5"

[feature.build.tasks.configure]
cmd = [
"cmake",
# The source is in the root directory
"-S .",
# We want to build in the build directory
"-B build",
]

[feature.build.tasks.build]
cmd = ["cmake", "--build", "build"]

## Tests

[feature.tests.tasks.tests]
depends-on = ["configure", "build"]
cwd = "build"
cmd = "ctest"

## Coverage

[feature.coverage.dependencies]
lcov = ">=1.16,<2"

[feature.coverage.tasks.configure-coverage]
cmd = [
"cmake",
"-DCMAKE_BUILD_TYPE=Coverage",
# The source is in the root directory
"-S .",
# We want to build in the build directory
"-B build",
]

[feature.coverage.tasks.coverage]
depends-on = ["configure-coverage"]
cmd = ["cmake", "--build", "build", "--target", "coverage_html"]

[feature.coverage.tasks.tests-coverage]
# Generate the coverage report and then run tests under the same configuration
depends-on = ["coverage"]
cwd = "build"
cmd = "ctest"

[environments]
dev = ["build", "tests", "coverage"]
22 changes: 22 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Get googletest
# https://google.github.io/googletest/quickstart-cmake.html
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

include(GoogleTest)
include(${CMAKE_SOURCE_DIR}/tests/Coverage.cmake)

# Add Tests
function(add_gtest test_name)
add_executable(${test_name} ${test_name}.cpp)
target_link_libraries(${test_name} GTest::gtest_main)
gtest_discover_tests(${test_name})
endfunction()

add_gtest(airy)
30 changes: 30 additions & 0 deletions tests/Coverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")

# Enable coverage compilation option
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /coverage")
endif()

# Add custom targets for generating coverage reports
add_custom_target(coverage
COMMAND lcov --capture --directory . --output-file coverage.info
COMMAND lcov --output-file coverage.info --extract coverage.info '*/include/xsf/*'
COMMAND lcov --list coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating coverage report"
)

# Generate coverage reports in HTML format
add_custom_target(coverage_html
COMMAND genhtml --demangle-cpp --legend coverage.info --output-directory coverage_report
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating HTML coverage report"
)
add_dependencies(coverage_html coverage)

endif() # CMAKE_BUILD_TYPE=Coverage
46 changes: 46 additions & 0 deletions tests/airy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <limits>
#include <complex>
#include <gtest/gtest.h>
#include <xsf/airy.h>

TEST(Airy, BasicAssertions) {
const double nan64 = std::numeric_limits<double>::quiet_NaN();
const std::complex<double> nan64c(std::nan(""), std::nan(""));
double x, ai, aip, bi, bip;

x = 0.0;
xsf::airy(x, ai, aip, bi, bip);
EXPECT_NE(ai, nan64);
EXPECT_NE(aip, nan64);
EXPECT_NE(bi, nan64);
EXPECT_NE(bip, nan64);

xsf::airye(x, ai, aip, bi, bip);
EXPECT_NE(ai, nan64);
EXPECT_NE(aip, nan64);
EXPECT_NE(bi, nan64);
EXPECT_NE(bip, nan64);

double apt, bpt, ant, bnt;
x = 1.0;
xsf::itairy(x, apt, bpt, ant, bnt);
EXPECT_NE(apt, nan64);
EXPECT_NE(bpt, nan64);
EXPECT_NE(ant, nan64);
EXPECT_NE(bnt, nan64);

// std::complex
std::complex<double> z, cai, caip, cbi, cbip;
z = 0.0;
xsf::airy(z, cai, caip, cbi, cbip);
EXPECT_NE(cai, nan64c);
EXPECT_NE(caip, nan64c);
EXPECT_NE(cbi, nan64c);
EXPECT_NE(cbip, nan64c);

xsf::airye(z, cai, caip, cbi, cbip);
EXPECT_NE(cai, nan64c);
EXPECT_NE(caip, nan64c);
EXPECT_NE(cbi, nan64c);
EXPECT_NE(cbip, nan64c);
}