Skip to content
Merged
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
32 changes: 10 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@
# make layout Rust layout(layout_file)
# make json Go json 扩展(json-rwirext 可执行文件)
# make oldhero Go 旧 runtime(kvlang-go,兼容保留,即将归档)
# make shm 链 kvspace-c 后端(SHM,默认,= all 的后端组件)
# make durable 链 kvspace_durable 后端(redis/fs/s3)
# make test durable 后端全量 tutorial 回归
# make test 全量 tutorial 回归
# make install 一次性安装产物到最终态目录(.so→/usr/lib,可执行→/usr/bin,头→/usr/include/kvlang/)
# make all 全部(shm 后端 + json)
# make all 全部(runtime + term + layout + json)
# make clean 清理 bin/ 与各构建目录
# 切换后端只需 make shm / make durable:runtime 经 cmake 重配、layout 经环境变量重建
# kvspace 后端由 libkvspace dispatch 前端按 DSN 运行时选择,不再编译期切换

BIN := bin
KVSPACE_LIB ?= kvspace-c

.PHONY: all runtime term layout json oldhero shm durable test install clean
.PHONY: all runtime term layout json oldhero test install clean

all: runtime term layout json

shm: runtime term layout

durable: KVSPACE_LIB := kvspace_durable
durable: runtime term layout

test: durable
test: all
python3 tutorial/test.py --no-build

runtime:
cmake -S runtime -B build/runtime -DCMAKE_BUILD_TYPE=Release -DKVSPACE_LIB=$(KVSPACE_LIB)
cmake -S runtime -B build/runtime -DCMAKE_BUILD_TYPE=Release
cmake --build build/runtime --target kvlang_runtime -j

term:
KVLANG_KVSPACE_LIB=$(KVSPACE_LIB) cargo build --release --manifest-path runtime-rwirext_example/rust/term/Cargo.toml
cargo build --release --manifest-path runtime-rwirext_example/rust/term/Cargo.toml
cp runtime-rwirext_example/rust/term/target/release/kvlang $(BIN)/kvlang

layout:
KVLANG_KVSPACE_LIB=$(KVSPACE_LIB) cargo build --release --manifest-path layout/Cargo.toml --example layout_file
KVLANG_KVSPACE_LIB=$(KVSPACE_LIB) cargo build --release --manifest-path layout/Cargo.toml
cargo build --release --manifest-path layout/Cargo.toml --example layout_file
cargo build --release --manifest-path layout/Cargo.toml
cp layout/target/release/examples/layout_file $(BIN)/

install:
Expand All @@ -48,11 +40,7 @@ install:
install -m 644 runtime/include/kvlang_runtime.h runtime/include/kvlang_rwirext.h /usr/include/kvlang/

json:
ifeq ($(KVSPACE_LIB),kvspace_durable)
cd runtime-rwirext_example/go/json && CGO_LDFLAGS="-L$(CURDIR)/../kvspace-durable/target/release -lkvspace_durable -Wl,--disable-new-dtags -Wl,-rpath,$(CURDIR)/../kvspace-durable/target/release" go build -o ../../../bin/json-rwirext ./cmd/
else
cd runtime-rwirext_example/go/json && CGO_LDFLAGS="-L$(CURDIR)/../kvspace-c/build -lkvspace-c -Wl,--disable-new-dtags -Wl,-rpath,$(CURDIR)/../kvspace-c/build -Wl,-rpath,$(CURDIR)/../blockmalloc/build -Wl,-rpath,$(CURDIR)/../slotsboxmalloc/build" go build -o ../../../bin/json-rwirext ./cmd/
endif
cd runtime-rwirext_example/go/json && CGO_LDFLAGS="-lkvspace" go build -o ../../../bin/json-rwirext ./cmd/

oldhero:
cd oldhero && go build -ldflags="-s -w" -o ../bin/kvlang-go ./cmd/kvlang/
Expand Down
18 changes: 3 additions & 15 deletions layout/build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
// 链接 kvspace 动态库(cdylib)。布局侧只通过 extern "C" ABI 调用
// 依赖 .so 已由 ci/deps.sh 安装到 /usr/lib;默认 kvspace-durable,KVLANG_KVSPACE_LIB=kvspace-c 时用 SHM 版
// 链接 kvspace dispatch 前端(已安装 /usr/lib)。布局侧只通过 extern "C" ABI 调用
// 运行期由前端按 DSN 选后端(shm://→kvspace-c,其余→kvspace-durable)
fn main() {
println!("cargo:rerun-if-env-changed=KVLANG_KVSPACE_LIB");
let manifest = env!("CARGO_MANIFEST_DIR");
let array2d = format!("{manifest}/../.."); // array2d 工作区
let lib = std::env::var("KVLANG_KVSPACE_LIB").unwrap_or_else(|_| "kvspace_durable".into());
let dir = if lib == "kvspace_durable" {
format!("{array2d}/kvspace-durable/target/release")
} else {
format!("{array2d}/kvspace-c/build")
};
println!("cargo:rustc-link-search=native={dir}");
println!("cargo:rustc-link-lib=dylib={lib}");
println!("cargo:rustc-link-arg=-Wl,--disable-new-dtags");
println!("cargo:rustc-link-arg=-Wl,-rpath,{dir}");
println!("cargo:rustc-link-lib=dylib=kvspace");
}
1 change: 0 additions & 1 deletion layout/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn lower_for_with_cont(
let idx_slot = lg.tmp();
let cond_slot = lg.tmp();
let len_slot = lg.tmp();
let keys_slot = lg.tmp();
let key_slot = lg.tmp();
let is_obj = s.iter.op == "obj"
|| s.iter.op == "map"
Expand Down
27 changes: 3 additions & 24 deletions runtime-rwirext_example/rust/term/build.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
// 链接 C runtime(libkvlang_runtime.so)+ kvspace 后端(扩展宿主自连 kvspace)。
// 产物统一在 kvlang/bin/,后端由 KVLANG_KVSPACE_LIB 选(对齐 runtime/layout),不 hardcode 绝对路径
// 链接 C runtime(libkvlang_runtime.so,bin/)+ kvspace dispatch 前端(已安装 /usr/lib)。
// 产物统一在 kvlang/bin/;kvspace 后端由前端按 DSN 运行时选择
fn main() {
println!("cargo:rerun-if-env-changed=KVLANG_KVSPACE_LIB");
let manifest = env!("CARGO_MANIFEST_DIR");
let bin = format!("{manifest}/../../../bin"); // kvlang/bin
let array2d = format!("{manifest}/../../../.."); // array2d 工作区

println!("cargo:rustc-link-search=native={bin}");
println!("cargo:rustc-link-lib=dylib=kvlang_runtime");

let backend = std::env::var("KVLANG_KVSPACE_LIB").unwrap_or_else(|_| "kvspace-c".to_string());
let (lib, dirs) = if backend == "kvspace_durable" {
("kvspace_durable", vec![format!("{array2d}/kvspace-durable/target/release")])
} else {
// kvspace-c 依赖 blockmalloc/slotsboxmalloc,需一并入 rpath(DT_RPATH 传递)
(
"kvspace-c",
vec![
format!("{array2d}/kvspace-c/build"),
format!("{array2d}/blockmalloc/build"),
format!("{array2d}/slotsboxmalloc/build"),
],
)
};
println!("cargo:rustc-link-search=native={}", dirs[0]);
println!("cargo:rustc-link-lib=dylib={lib}");
println!("cargo:rustc-link-lib=dylib=kvspace");

println!("cargo:rustc-link-arg=-Wl,--disable-new-dtags"); // rpath 转 DT_RPATH,传递解析 kvspace 的子依赖
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");
for d in &dirs {
println!("cargo:rustc-link-arg=-Wl,-rpath,{d}");
}
}
15 changes: 4 additions & 11 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# ── kvspace 后端(kvspace-c 或 kvspace_durable,均导出同一 C ABI)────
set(KVSPACE_LIB "kvspace-c" CACHE STRING "kvspace 后端库:kvspace-c / kvspace_durable")

# ── 输出统一到 bin/ ──────────────────────────────────────────────
set(BIN_DIR "${CMAKE_SOURCE_DIR}/../bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BIN_DIR}")
Expand All @@ -20,12 +17,8 @@ add_library(kvlang_runtime SHARED
target_include_directories(kvlang_runtime PUBLIC include src)
target_compile_definitions(kvlang_runtime PRIVATE _GNU_SOURCE)

if(KVSPACE_LIB STREQUAL "kvspace-c")
target_link_libraries(kvlang_runtime PRIVATE kvspace-c blockmalloc slotsboxmalloc)
else()
target_link_libraries(kvlang_runtime PRIVATE kvspace_durable)
endif()
target_link_libraries(kvlang_runtime PRIVATE m pthread)
# --export-dynamic 供 kvlang(term 扩展)找符号;--disable-new-dtags 使 rpath 转 DT_RPATH(传递),
# 让 runtime → kvspace-c → blockmalloc/slotsboxmalloc 的传递依赖能被 runtime 的 rpath 找到。
# 链接 kvspace dispatch 前端(已安装 /usr/lib),运行期按 DSN 选后端,编译期不再选后端。
target_link_libraries(kvlang_runtime PRIVATE kvspace m pthread)

# --export-dynamic 供 kvlang(term 扩展)找符号;--disable-new-dtags 使 rpath 转 DT_RPATH(传递)。
set_target_properties(kvlang_runtime PROPERTIES LINK_FLAGS "-Wl,--export-dynamic -Wl,--disable-new-dtags")
Loading