Skip to content

Commit b1c474e

Browse files
authored
Pass missing cmake sccache-related flags (#6032)
See [docs](https://github.com/mozilla-actions/sccache-action/tree/v0.0.9/?tab=readme-ov-file#cc-code). This change takes the cxx build from ~5 minutes to just over 1 minute. --------- Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 6838253 commit b1c474e

File tree

5 files changed

+123
-26
lines changed

5 files changed

+123
-26
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -670,26 +670,30 @@ jobs:
670670
- extras=s3-cache
671671
- tag=cxx-build
672672
steps:
673+
- uses: runs-on/action@v2
674+
with:
675+
sccache: s3
673676
- uses: actions/checkout@v6
674-
- uses: ./.github/actions/setup-rust
677+
- id: setup-rust
678+
uses: ./.github/actions/setup-rust
675679
with:
676680
repo-token: ${{ secrets.GITHUB_TOKEN }}
681+
timestamp: "true"
682+
cache-suffix: "cxx"
677683
- name: Build and run C++ unit tests
678-
working-directory: vortex-cxx/
679684
run: |
680-
mkdir -p build
681-
cd build
682-
cmake -DVORTEX_ENABLE_TESTING=ON -DVORTEX_ENABLE_ASAN=ON ..
683-
cmake --build . --parallel $(nproc)
684-
ctest -V
685+
mkdir -p vortex-cxx/build
686+
cmake -S vortex-cxx -B vortex-cxx/build -DVORTEX_ENABLE_TESTING=ON -DVORTEX_ENABLE_ASAN=ON
687+
cmake --build vortex-cxx/build --parallel $(nproc)
688+
ctest --test-dir vortex-cxx/build -V
685689
- name: Build and run the example in release mode
686-
working-directory: vortex-cxx/examples
687690
run: |
688-
mkdir -p build
689-
cd build
690-
cmake -DCMAKE_BUILD_TYPE=Release ..
691-
cmake --build . --parallel $(nproc)
692-
./hello-vortex ../goldenfiles/example.vortex
691+
cmake -S vortex-cxx/examples -B vortex-cxx/examples/build -DCMAKE_BUILD_TYPE=Release
692+
cmake --build vortex-cxx/examples/build --parallel $(nproc)
693+
vortex-cxx/examples/build/hello-vortex vortex-cxx/examples/goldenfiles/example.vortex
694+
- name: Prune cache
695+
if: ${{ github.ref_name == 'develop' && steps.setup-rust.outputs.deps-cache-hit != 'true' }}
696+
run: cargo sweep --file
693697

694698
wasm-integration:
695699
name: "wasm-integration"

vortex-cxx/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ project(vortex)
1111
set(CMAKE_CXX_STANDARD 17)
1212
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1313

14+
find_program(SCCACHE_PROGRAM sccache)
15+
if (SCCACHE_PROGRAM)
16+
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
17+
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
18+
message(STATUS "Sccache found: ${SCCACHE_PROGRAM}")
19+
else ()
20+
message(STATUS "Sccache not found")
21+
endif ()
22+
1423
if (NOT CMAKE_BUILD_TYPE)
1524
set(CMAKE_BUILD_TYPE Debug)
1625
endif()

vortex-cxx/examples/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ project(vortex-examples)
88
set(CMAKE_CXX_STANDARD 17)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11+
12+
find_program(SCCACHE_PROGRAM sccache)
13+
if (SCCACHE_PROGRAM)
14+
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
15+
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PROGRAM}")
16+
message(STATUS "Sccache found: ${SCCACHE_PROGRAM}")
17+
else ()
18+
message(STATUS "Sccache not found")
19+
endif ()
20+
1121
include(FetchContent)
1222
FetchContent_Declare(
1323
vortex
@@ -22,13 +32,6 @@ if(APPLE)
2232
set(APPLE_LINK_FLAGS "-framework CoreFoundation -framework Security")
2333
endif()
2434

25-
target_link_libraries(hello-vortex PRIVATE vortex ${APPLE_LINK_FLAGS})
2635

27-
add_custom_target(convert-parquet
28-
COMMAND cargo run -p vortex-tui convert ${CMAKE_CURRENT_SOURCE_DIR}/goldenfiles/example.parquet
29-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
30-
COMMENT "Converting example.parquet using vortex-tui"
31-
VERBATIM
32-
)
36+
target_link_libraries(hello-vortex PRIVATE vortex ${APPLE_LINK_FLAGS})
3337

34-
add_dependencies(hello-vortex convert-parquet)
-512 Bytes
Binary file not shown.

vortex-cxx/examples/hello-vortex.cpp

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,113 @@
33

44
#include "nanoarrow/common/inline_types.h"
55
#include "nanoarrow/hpp/unique.hpp"
6+
#include "nanoarrow/nanoarrow.hpp"
67
#include "vortex/file.hpp"
78
#include "vortex/scan.hpp"
9+
#include "vortex/write_options.hpp"
810
#include <cassert>
11+
#include <cstdint>
12+
#include <filesystem>
913
#include <iostream>
14+
#include <vector>
1015

11-
int main(int argc, char *argv[]) {
12-
if (argc != 2) {
13-
std::cerr << "Usage: " << argv[0] << " <vortex_file>" << '\n';
14-
return 1;
16+
/// Create test data with structure {a: [10, 20, 30, 40, 50], b: [100, 200, 300, 400, 500]}
17+
ArrowArrayStream CreateTestDataStream() {
18+
// Create a simple two-column struct with int32 data
19+
// Schema: struct{a: int32, b: int32}
20+
nanoarrow::UniqueSchema schema;
21+
ArrowSchemaInit(schema.get());
22+
NANOARROW_THROW_NOT_OK(ArrowSchemaSetType(schema.get(), NANOARROW_TYPE_STRUCT));
23+
NANOARROW_THROW_NOT_OK(ArrowSchemaAllocateChildren(schema.get(), 2));
24+
ArrowSchemaInit(schema->children[0]);
25+
ArrowSchemaInit(schema->children[1]);
26+
NANOARROW_THROW_NOT_OK(ArrowSchemaSetName(schema->children[0], "a"));
27+
NANOARROW_THROW_NOT_OK(ArrowSchemaSetType(schema->children[0], NANOARROW_TYPE_INT32));
28+
NANOARROW_THROW_NOT_OK(ArrowSchemaSetName(schema->children[1], "b"));
29+
NANOARROW_THROW_NOT_OK(ArrowSchemaSetType(schema->children[1], NANOARROW_TYPE_INT32));
30+
31+
// Create arrays for each field
32+
nanoarrow::UniqueArray field_a, field_b;
33+
NANOARROW_THROW_NOT_OK(ArrowArrayInitFromType(field_a.get(), NANOARROW_TYPE_INT32));
34+
NANOARROW_THROW_NOT_OK(ArrowArrayInitFromType(field_b.get(), NANOARROW_TYPE_INT32));
35+
36+
// Reserve for 5 elements
37+
NANOARROW_THROW_NOT_OK(ArrowArrayStartAppending(field_a.get()));
38+
NANOARROW_THROW_NOT_OK(ArrowArrayStartAppending(field_b.get()));
39+
40+
// Add data: a=[10, 20, 30, 40, 50], b=[100, 200, 300, 400, 500]
41+
std::vector<int32_t> data_a = {10, 20, 30, 40, 50};
42+
std::vector<int32_t> data_b = {100, 200, 300, 400, 500};
43+
for (size_t i = 0; i < data_a.size(); ++i) {
44+
NANOARROW_THROW_NOT_OK(ArrowArrayAppendInt(field_a.get(), data_a[i]));
45+
NANOARROW_THROW_NOT_OK(ArrowArrayAppendInt(field_b.get(), data_b[i]));
1546
}
16-
std::string vortex_file = argv[1];
47+
48+
NANOARROW_THROW_NOT_OK(
49+
ArrowArrayFinishBuilding(field_a.get(), NANOARROW_VALIDATION_LEVEL_NONE, nullptr));
50+
NANOARROW_THROW_NOT_OK(
51+
ArrowArrayFinishBuilding(field_b.get(), NANOARROW_VALIDATION_LEVEL_NONE, nullptr));
52+
53+
// Create struct array
54+
nanoarrow::UniqueArray struct_array;
55+
NANOARROW_THROW_NOT_OK(ArrowArrayInitFromType(struct_array.get(), NANOARROW_TYPE_STRUCT));
56+
NANOARROW_THROW_NOT_OK(ArrowArrayAllocateChildren(struct_array.get(), 2));
57+
struct_array->length = 5;
58+
ArrowArrayMove(field_a.get(), struct_array->children[0]);
59+
ArrowArrayMove(field_b.get(), struct_array->children[1]);
60+
61+
// Create vector and move array into it
62+
std::vector<nanoarrow::UniqueArray> arrays;
63+
arrays.push_back(std::move(struct_array));
64+
65+
// Create stream
66+
ArrowArrayStream stream;
67+
nanoarrow::VectorArrayStream vector_stream(schema.get(), std::move(arrays));
68+
vector_stream.ToArrayStream(&stream);
69+
70+
return stream;
71+
}
72+
73+
int main() {
74+
// Create a temporary file path
75+
std::filesystem::path temp_dir = std::filesystem::temp_directory_path();
76+
std::string vortex_file = (temp_dir / "hello_vortex_example.vortex").string();
77+
78+
std::cout << "=== Vortex C++ Example ===" << '\n';
79+
std::cout << "Writing to: " << vortex_file << '\n';
80+
81+
// Write test data to a Vortex file
82+
{
83+
auto stream = CreateTestDataStream();
84+
vortex::VortexWriteOptions write_options;
85+
write_options.WriteArrayStream(stream, vortex_file);
86+
std::cout << "Wrote test data to file" << '\n';
87+
}
88+
1789
auto check_stream = [](ArrowArrayStream &stream) {
1890
nanoarrow::UniqueArray array;
1991
int get_next_result = stream.get_next(&stream, array.get());
2092
assert(get_next_result == 0);
2193
std::cout << "Number of rows: " << array->length << '\n';
2294
std::cout << "Number of columns in schema: " << array->n_children << '\n';
2395
};
96+
2497
// 1. Classic C++ builder pattern
98+
std::cout << "\n1. Classic C++ builder pattern:" << '\n';
2599
{
26100
auto builder = vortex::VortexFile::Open(vortex_file).CreateScanBuilder();
27101
builder.WithLimit(3);
28102
auto stream = std::move(builder).IntoStream();
29103
check_stream(stream);
30104
}
31105
// 2. One-line Rusty function chain
106+
std::cout << "\n2. One-line Rusty function chain:" << '\n';
32107
{
33108
auto stream = vortex::VortexFile::Open(vortex_file).CreateScanBuilder().WithLimit(3).IntoStream();
34109
check_stream(stream);
35110
}
36111
// 3. Conditionally set the builder
112+
std::cout << "\n3. Conditionally set the builder:" << '\n';
37113
{
38114
auto limit = 1;
39115
auto builder = vortex::VortexFile::Open(vortex_file).CreateScanBuilder();
@@ -46,5 +122,10 @@ int main(int argc, char *argv[]) {
46122
auto stream = std::move(builder).IntoStream();
47123
check_stream(stream);
48124
}
125+
126+
// Clean up
127+
std::filesystem::remove(vortex_file);
128+
std::cout << "\nCleaned up temporary file" << '\n';
129+
49130
return 0;
50131
}

0 commit comments

Comments
 (0)