Skip to content

Commit 83dabc6

Browse files
authored
Merge pull request #2 from GraphBLAS/brock/fixes-for-macos
Add CI, small fixes to work with Mac OS.
2 parents 73a57a8 + 627b754 commit 83dabc6

File tree

8 files changed

+108
-28
lines changed

8 files changed

+108
-28
lines changed

.github/workflows/ci.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "CI"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
checks:
12+
runs-on: 'ubuntu-latest'
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.12'
18+
cache: 'pip'
19+
- run: pip install -r requirements.txt
20+
- name: Checks
21+
uses: pre-commit/[email protected]
22+
23+
gcc:
24+
runs-on: 'ubuntu-latest'
25+
strategy:
26+
matrix:
27+
cxx: [g++-12, clang++]
28+
name: ${{ matrix.cxx }}
29+
env:
30+
CXX: ${{ matrix.cxx }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: CMake
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install libhdf5-dev g++-12
37+
cmake -B build
38+
- name: Build
39+
run: make -C build -j `nproc`
40+
- name: Test
41+
run: |
42+
./build/test/gtest/binsparse-tests
43+
44+
macos:
45+
runs-on: 'macos-latest'
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: CMake
49+
run: |
50+
brew install hdf5
51+
cmake -B build
52+
- name: Build
53+
run: make -C build -j
54+
- name: Test
55+
run: |
56+
./build/test/gtest/binsparse-tests

CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77
add_subdirectory(include)
88

9-
find_package(HDF5 REQUIRED COMPONENTS CXX)
10-
target_link_libraries(binsparse INTERFACE ${HDF5_CXX_LIBRARIES})
11-
target_include_directories(binsparse INTERFACE . ${HDF5_INCLUDE_DIRS})
9+
find_package(HDF5 REQUIRED COMPONENTS C CXX)
10+
target_link_libraries(binsparse INTERFACE ${HDF5_C_LIBRARIES} hdf5::hdf5_cpp)
1211

1312
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
1413
# Dependencies needed only for examples/test

include/binsparse/hdf5_tools.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <H5Cpp.h>
44
#include <cassert>
5+
#include <cstdint>
56
#include <ranges>
67
#include <type_traits>
78
#include <vector>

include/binsparse/type_info.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ struct type_info<uint64_t> {
4545
}
4646
};
4747

48-
template <>
49-
struct type_info<std::size_t> {
48+
template <typename T>
49+
requires std::is_same_v<T, std::size_t>
50+
struct type_info<T> {
5051
static constexpr auto label() noexcept {
5152
return "uint64";
5253
}

test/gtest/CMakeLists.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ function(download_data url file_name)
55
${url}
66
${DATASET_ARCHIVE})
77

8-
string(REPLACE
8+
string(REPLACE
99
".tar.gz" ""
10-
DATSET_DIR
10+
DATASET_DIR
1111
${DATASET_ARCHIVE})
1212

13-
file(ARCHIVE_EXTRACT INPUT
14-
${DATASET_ARCHIVE}
15-
${DATASET_DIR})
13+
cmake_path(REMOVE_FILENAME DATASET_DIR)
14+
15+
file(ARCHIVE_EXTRACT INPUT ${DATASET_ARCHIVE} DESTINATION ${DATASET_DIR})
16+
17+
message(STATUS "Downloading file ${DATASET_ARCHIVE}, extracting to ${DATASET_DIR}.")
1618
endfunction()
1719

1820
enable_testing()

test/gtest/coo_test.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include <gtest/gtest.h>
2-
3-
#include <fmt/core.h>
4-
1+
#include "util.hpp"
52
#include <binsparse/binsparse.hpp>
6-
7-
inline std::vector file_paths({"1138_bus/1138_bus.mtx",
8-
"chesapeake/chesapeake.mtx",
9-
"mouse_gene/mouse_gene.mtx"});
3+
#include <filesystem>
4+
#include <fmt/core.h>
5+
#include <gtest/gtest.h>
106

117
TEST(BinsparseReadWrite, COOFormat) {
128
using T = float;
139
using I = std::size_t;
1410

1511
std::string binsparse_file = "out.bsp.hdf5";
1612

17-
for (auto&& file_path : file_paths) {
13+
auto base_path = find_prefix(files.front());
14+
15+
for (auto&& file : files) {
16+
auto file_path = base_path + file;
1817
auto x = binsparse::__detail::mmread<
1918
T, I, binsparse::__detail::coo_matrix_owning<T, I>>(file_path);
2019

@@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, COOFormat) {
4645
delete matrix_.rowind;
4746
delete matrix_.colind;
4847
}
48+
49+
std::filesystem::remove(binsparse_file);
4950
}

test/gtest/csr_test.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
#include <gtest/gtest.h>
2-
3-
#include <fmt/core.h>
4-
1+
#include "util.hpp"
52
#include <binsparse/binsparse.hpp>
6-
7-
inline std::vector file_paths({"1138_bus/1138_bus.mtx",
8-
"chesapeake/chesapeake.mtx",
9-
"mouse_gene/mouse_gene.mtx"});
3+
#include <filesystem>
4+
#include <fmt/core.h>
5+
#include <gtest/gtest.h>
106

117
TEST(BinsparseReadWrite, CSRFormat) {
128
using T = float;
139
using I = std::size_t;
1410

1511
std::string binsparse_file = "out.bsp.hdf5";
1612

17-
for (auto&& file_path : file_paths) {
13+
auto base_path = find_prefix(files.front());
14+
15+
for (auto&& file : files) {
16+
auto file_path = base_path + file;
1817
auto x = binsparse::__detail::mmread<
1918
T, I, binsparse::__detail::csr_matrix_owning<T, I>>(file_path);
2019

@@ -46,4 +45,6 @@ TEST(BinsparseReadWrite, CSRFormat) {
4645
delete matrix_.row_ptr;
4746
delete matrix_.colind;
4847
}
48+
49+
std::filesystem::remove(binsparse_file);
4950
}

test/gtest/util.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
#include <string>
5+
#include <vector>
6+
7+
inline std::vector<std::string> files({"data/1138_bus/1138_bus.mtx",
8+
"data/chesapeake/chesapeake.mtx",
9+
"data/mouse_gene/mouse_gene.mtx"});
10+
11+
inline std::string find_prefix(std::string file_name) {
12+
if (std::filesystem::exists("../../" + file_name)) {
13+
return "../../";
14+
} else if (std::filesystem::exists("build/" + file_name)) {
15+
return "build/";
16+
} else {
17+
return "";
18+
}
19+
}

0 commit comments

Comments
 (0)