Skip to content
Open
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
46 changes: 33 additions & 13 deletions sidemantic-duckdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,43 @@ include_directories(src/include)
set(SIDEMANTIC_RS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../sidemantic-rs")
set(SIDEMANTIC_CARGO_TARGET_DIR "${SIDEMANTIC_RS_DIR}/target" CACHE PATH "Cargo target directory for sidemantic-rs")
set(SIDEMANTIC_CARGO_PROFILE "release" CACHE STRING "Cargo profile used for the sidemantic-rs static library")
set(SIDEMANTIC_CARGO_TARGET "" CACHE STRING "Rust target triple for sidemantic-rs static library")
set(SIDEMANTIC_RUST_NATIVE_STATIC_LIBS "" CACHE STRING "Additional native libraries required by the sidemantic-rs staticlib")
set(SIDEMANTIC_INCLUDE "${SIDEMANTIC_RS_DIR}/include")

if(WIN32)
if(NOT SIDEMANTIC_CARGO_TARGET AND DEFINED Rust_CARGO_TARGET)
set(SIDEMANTIC_CARGO_TARGET "${Rust_CARGO_TARGET}" CACHE STRING "Rust target triple for sidemantic-rs static library" FORCE)
endif()

if(SIDEMANTIC_CARGO_TARGET MATCHES "pc-windows-msvc$")
set(SIDEMANTIC_STATICLIB_NAME "sidemantic.lib")
elseif(SIDEMANTIC_CARGO_TARGET)
set(SIDEMANTIC_STATICLIB_NAME "libsidemantic.a")
elseif(WIN32)
set(SIDEMANTIC_STATICLIB_NAME "sidemantic.lib")
else()
set(SIDEMANTIC_STATICLIB_NAME "libsidemantic.a")
endif()

set(SIDEMANTIC_LIB "${SIDEMANTIC_CARGO_TARGET_DIR}/${SIDEMANTIC_CARGO_PROFILE}/${SIDEMANTIC_STATICLIB_NAME}")
if(SIDEMANTIC_CARGO_TARGET)
set(SIDEMANTIC_LIB_DIR "${SIDEMANTIC_CARGO_TARGET_DIR}/${SIDEMANTIC_CARGO_TARGET}/${SIDEMANTIC_CARGO_PROFILE}")
else()
set(SIDEMANTIC_LIB_DIR "${SIDEMANTIC_CARGO_TARGET_DIR}/${SIDEMANTIC_CARGO_PROFILE}")
endif()

set(SIDEMANTIC_LIB "${SIDEMANTIC_LIB_DIR}/${SIDEMANTIC_STATICLIB_NAME}")
message(STATUS "sidemantic-rs cargo target: '${SIDEMANTIC_CARGO_TARGET}'")
message(STATUS "sidemantic-rs static library: ${SIDEMANTIC_LIB}")

find_program(CARGO_EXECUTABLE cargo)
if(NOT CARGO_EXECUTABLE)
message(FATAL_ERROR "cargo is required to build the sidemantic DuckDB extension")
endif()

set(SIDEMANTIC_CARGO_BUILD_ARGS build --manifest-path "${SIDEMANTIC_RS_DIR}/Cargo.toml" --lib)
if(SIDEMANTIC_CARGO_TARGET)
list(APPEND SIDEMANTIC_CARGO_BUILD_ARGS --target "${SIDEMANTIC_CARGO_TARGET}")
endif()
if(SIDEMANTIC_CARGO_PROFILE STREQUAL "release")
list(APPEND SIDEMANTIC_CARGO_BUILD_ARGS --release)
elseif(NOT SIDEMANTIC_CARGO_PROFILE STREQUAL "debug")
Expand Down Expand Up @@ -60,22 +81,21 @@ build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
add_dependencies(${EXTENSION_NAME} sidemantic_rust_staticlib)
add_dependencies(${LOADABLE_EXTENSION_NAME} sidemantic_rust_staticlib)

# Link the Rust static library
target_link_libraries(${EXTENSION_NAME} ${SIDEMANTIC_LIB})
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${SIDEMANTIC_LIB})

# On macOS, we need to link against some system frameworks
# Link the Rust static library and native libraries rustc would normally pass
# when producing a final binary for the target platform.
if(APPLE)
target_link_libraries(${EXTENSION_NAME} "-framework Security" "-framework CoreFoundation")
target_link_libraries(${LOADABLE_EXTENSION_NAME} "-framework Security" "-framework CoreFoundation")
list(APPEND SIDEMANTIC_RUST_NATIVE_STATIC_LIBS "-framework Security" "-framework CoreFoundation")
endif()

# On Linux, we need pthread and dl
if(UNIX AND NOT APPLE)
target_link_libraries(${EXTENSION_NAME} pthread dl)
target_link_libraries(${LOADABLE_EXTENSION_NAME} pthread dl)
list(APPEND SIDEMANTIC_RUST_NATIVE_STATIC_LIBS pthread dl m)
endif()
if(WIN32 OR SIDEMANTIC_CARGO_TARGET MATCHES "pc-windows")
list(APPEND SIDEMANTIC_RUST_NATIVE_STATIC_LIBS advapi32 ws2_32 userenv bcrypt ntdll)
endif()

target_link_libraries(${EXTENSION_NAME} ${SIDEMANTIC_LIB} ${SIDEMANTIC_RUST_NATIVE_STATIC_LIBS})
target_link_libraries(${LOADABLE_EXTENSION_NAME} ${SIDEMANTIC_LIB} ${SIDEMANTIC_RUST_NATIVE_STATIC_LIBS})

install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
Expand Down
45 changes: 32 additions & 13 deletions sidemantic-duckdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@ A DuckDB extension that adds a SQL-first semantic layer. Define metrics and dime

## Installation

Current builds are loaded from a local build or GitHub release artifact:

Start DuckDB with unsigned-extension loading enabled because these artifacts are not signed yet:

```bash
duckdb -unsigned
```

```sql
LOAD '/absolute/path/to/sidemantic.duckdb_extension';
```

For local development:

```bash
make deps DUCKDB_VERSION=v1.4.2
make
make test
./build/release/duckdb -unsigned
```

```sql
-- From community extensions (when published)
INSTALL sidemantic FROM community;
LOAD sidemantic;
LOAD 'build/release/extension/sidemantic/sidemantic.duckdb_extension';
```

For embedded clients, set DuckDB's `allow_unsigned_extensions` database configuration before opening the connection. Community extension installation is planned, but this repository does not yet publish the signed multi-platform artifacts required for `INSTALL sidemantic FROM community`.

## Quick Start (Pure SQL)

Define your semantic layer entirely in SQL, no YAML required:
Expand All @@ -32,7 +53,6 @@ INSERT INTO orders VALUES

-- 2. Define a semantic model
SEMANTIC CREATE MODEL orders_model (
name orders_model,
table orders,
primary_key order_id
);
Expand Down Expand Up @@ -67,12 +87,13 @@ Creates a new semantic model linked to a physical table.

```sql
SEMANTIC CREATE MODEL model_name (
name model_name,
table physical_table_name,
primary_key pk_column
);
```

The model name may also be repeated inside the body for compatibility, but it must match the name after `MODEL`.

### SEMANTIC CREATE METRIC

Defines a metric (aggregation) on the current model.
Expand Down Expand Up @@ -286,23 +307,21 @@ SELECT sidemantic_rewrite_sql('SELECT orders.revenue FROM orders');
## Building from Source

```bash
# Clone with submodules
git clone --recurse-submodules https://github.com/your-repo/sidemantic-duckdb.git
# From this repository checkout
cd sidemantic-duckdb

# Build the Rust library first
cd ../sidemantic-rs
cargo build --release
cd ../sidemantic-duckdb
# Fetch the DuckDB source version used by CI.
# extension-ci-tools is vendored in this directory and pinned to v1.4.2.
make deps DUCKDB_VERSION=v1.4.2

# Build the extension
# Build the extension. CMake builds the sibling sidemantic-rs static library automatically.
make

# Run tests
make test

# Use the extension
./build/release/duckdb
./build/release/duckdb -unsigned
```

## Architecture
Expand Down
2 changes: 1 addition & 1 deletion sidemantic-duckdb/demo.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Sidemantic DuckDB Extension Demo
-- Run with: ./build/release/duckdb < demo.sql
-- Run with: ./build/release/duckdb -unsigned < demo.sql

-- Load the extension
LOAD 'build/release/extension/sidemantic/sidemantic.duckdb_extension';
Expand Down
Loading
Loading