diff --git a/.gitignore b/.gitignore index 3c320008..c2e4cb9e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ compile_commands.json CTestTestfile.cmake _deps -*.db \ No newline at end of file +*.db +deps/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..77798ed3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rocksdb"] + path = rocksdb + url = https://github.com/facebook/rocksdb diff --git a/.idea/misc.xml b/.idea/misc.xml index e1f265e1..350e9b34 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a2cb6faf..9eeb35c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ chrono = "0.4" anyhow = "1.0" lazy_static = "1.4.0" thiserror = "1.0.30" -cozo-rocks = { path = "cozo-rocks" } \ No newline at end of file +cozorocks = { path = "cozorocks" } \ No newline at end of file diff --git a/build_rocksdb.sh b/build_rocksdb.sh new file mode 100644 index 00000000..4dbacfb1 --- /dev/null +++ b/build_rocksdb.sh @@ -0,0 +1,19 @@ +cd rocksdb || exit +make clean +INSTALL_DIR=$(readlink -f ../deps) +echo "$INSTALL_DIR" +rm -fr "$INSTALL_DIR" +mkdir "$INSTALL_DIR" + +export JEMALLOC_BASE=/opt/homebrew + +JEMALLOC_INCLUDE=" -I $JEMALLOC_BASE/include/" \ +JEMALLOC_LIB=" $JEMALLOC_BASE/lib/libjemalloc.a" \ +USE_RTTI=1 \ +USE_CLANG=1 \ +JEMALLOC=1 \ +PREFIX=$INSTALL_DIR \ +make install-static + +DEBUG_LEVEL=0 make libz.a libsnappy.a liblz4.a libzstd.a +mv ./*.a ../deps/lib \ No newline at end of file diff --git a/cozo-rocks/build.rs b/cozo-rocks/build.rs deleted file mode 100644 index ef1c55d9..00000000 --- a/cozo-rocks/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -fn main() { - cxx_build::bridge("src/lib.rs") - .file("src/cozorocks.cc") - .include("../rocksdb/include") - .include("include") - .flag_if_supported("-std=c++17") - .compile("cozo-rocks"); - - println!("cargo:rustc-link-search=rocksdb/"); - println!("cargo:rustc-link-lib=rocksdb"); - println!("cargo:rustc-link-lib=z"); - println!("cargo:rustc-link-lib=bz2"); - println!("cargo:rerun-if-changed=src/main.rs"); - println!("cargo:rerun-if-changed=src/cozorocks.cc"); - println!("cargo:rerun-if-changed=include/cozorocks.h"); -} \ No newline at end of file diff --git a/cozorocks/.gitignore b/cozorocks/.gitignore new file mode 100644 index 00000000..266fcfaf --- /dev/null +++ b/cozorocks/.gitignore @@ -0,0 +1,86 @@ +### CMake template +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + diff --git a/cozorocks/CMakeLists.txt b/cozorocks/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/cozo-rocks/Cargo.toml b/cozorocks/Cargo.toml similarity index 83% rename from cozo-rocks/Cargo.toml rename to cozorocks/Cargo.toml index b77e1d7b..46ba526d 100644 --- a/cozo-rocks/Cargo.toml +++ b/cozorocks/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cozo-rocks" +name = "cozorocks" version = "0.1.0" edition = "2021" diff --git a/cozo-rocks/src/cozorocks.cc b/cozorocks/bridge/cozorocks.cc similarity index 86% rename from cozo-rocks/src/cozorocks.cc rename to cozorocks/bridge/cozorocks.cc index 8061d805..d4fdbe8e 100644 --- a/cozo-rocks/src/cozorocks.cc +++ b/cozorocks/bridge/cozorocks.cc @@ -2,8 +2,8 @@ //// Created by Ziyang Hu on 2022/4/13. //// // -#include "../include/cozorocks.h" -#include "cozo-rocks/src/lib.rs.h" +#include "cozorocks.h" +#include "cozorocks/src/lib.rs.h" void write_status_impl(BridgeStatus &status, StatusCode code, StatusSubCode subcode, StatusSeverity severity, int bridge_code) { status.code = code; diff --git a/cozo-rocks/include/cozorocks.h b/cozorocks/bridge/cozorocks.h similarity index 100% rename from cozo-rocks/include/cozorocks.h rename to cozorocks/bridge/cozorocks.h diff --git a/cozorocks/build.rs b/cozorocks/build.rs new file mode 100644 index 00000000..b4966d26 --- /dev/null +++ b/cozorocks/build.rs @@ -0,0 +1,19 @@ +fn main() { + cxx_build::bridge("src/lib.rs") + .file("bridge/cozorocks.cc") + .include("../deps/include") + .include("bridge") + .flag_if_supported("-std=c++17") + .compile("cozorocks"); + + println!("cargo:rustc-link-search=deps/lib/"); + println!("cargo:rustc-link-lib=rocksdb"); + println!("cargo:rustc-link-lib=z"); + println!("cargo:rustc-link-lib=bz2"); + println!("cargo:rustc-link-lib=lz4"); + println!("cargo:rustc-link-lib=snappy"); + println!("cargo:rustc-link-lib=zstd"); + println!("cargo:rerun-if-changed=src/main.rs"); + println!("cargo:rerun-if-changed=bridge/cozorocks.cc"); + println!("cargo:rerun-if-changed=bridge/cozorocks.h"); +} \ No newline at end of file diff --git a/cozo-rocks/src/lib.rs b/cozorocks/src/lib.rs similarity index 100% rename from cozo-rocks/src/lib.rs rename to cozorocks/src/lib.rs diff --git a/rocksdb b/rocksdb new file mode 160000 index 00000000..ee6ee5ff --- /dev/null +++ b/rocksdb @@ -0,0 +1 @@ +Subproject commit ee6ee5ff08d32fb325d8768139305a3227025b0e diff --git a/src/lib.rs b/src/lib.rs index 27a921e7..4f1c9c06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -extern crate core; - // pub mod value; // pub mod typing; // pub mod env; @@ -13,4 +11,14 @@ extern crate core; // pub mod plan; pub mod relation; pub mod db; -pub mod error; \ No newline at end of file +pub mod error; + +#[cfg(test)] +mod tests { + #[test] + fn import() { + use cozorocks::*; + let _o = Options::default(); + println!("Hello"); + } +} \ No newline at end of file