Skip to content

Commit

Permalink
feat: upgraded to RDFOx 7.0 (still supporting 6.3b as well)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeluk committed Jan 26, 2024
1 parent 7488c63 commit 9b6fdd2
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol = "git"
git-fetch-with-cli = true # use the `git` executable for git operations

[patch.crates-io]
#rdf-store-rs = { path = "../rdf-store-rs" }
rdf-store-rs = { path = "../rdf-store-rs" }

[term]
color = "always"
Expand Down
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ remove_nested_parens = true
reorder_impl_items = true
reorder_imports = true
reorder_modules = true
required_version = "1.5.2"
required_version = "1.70"
space_after_colon = true
space_before_colon = false
spaces_around_ranges = false
Expand Down
19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ version = "0.1.11"
edition = "2021"
links = "RDFox-static"
authors = [
"Jacobus Geluk <jacobus.geluk@ekgf.org>",
"Marcelo Barbieri <marcelo.barbieri@agnos.ai>"
"Jacobus Geluk <jacobus.geluk@ekgf.org>",
"Marcelo Barbieri <marcelo.barbieri@agnos.ai>"
]
repository = "https://github.com/EKGF/rdfox-rs"
keywords = ["rdf", "sparql", "database", "graph-database", "datalog"]
Expand All @@ -26,16 +26,16 @@ bench = false

[dependencies]
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
tracing-log = { version = "0.1.3", features = ["env_logger"] }
env_logger = "0.10.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-log = { version = "0.2.0" }
env_logger = "0.11.0"
mime = "0.3.16"
lazy_static = "1.4.0"
thiserror = "1.0.31"
fancy-regex = "0.13.0"
colored = "2.0.0"
ignore = "0.4.18"
iref = "2.1.3"
iref = "3.1.3"
indoc = "2.0.0"
num_enum = "0.7.0"
nom = { version = "7.1.1", optional = true }
Expand All @@ -44,8 +44,8 @@ r2d2 = "0.8.1"
iri-string = { version = "0.7.0", features = ["serde", "alloc"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
rdf-store-rs = { version = "0.0.9", features = ["serde"] }
owo-colors = { version = "4.0.0", features = ["supports-colors"] }
rdf-store-rs = { version = "0.0.10", features = ["serde"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.rdftk_iri]
version = "0.1.9"
Expand All @@ -66,7 +66,7 @@ bindgen = "0.69.2"
rustc-args = ["--cfg", "docsrs"]

[features]
default = ["nom", "rdfox-6-3b"]
default = ["nom", "rdfox-7-0", "rdfox-dylib"]
rdftk-support = ["rdftk_iri/uuid_iri"]
nom-support = ["nom"]
#
Expand All @@ -79,5 +79,6 @@ rdfox-dylib = []
rdfox-6-2 = []
rdfox-6-3a = []
rdfox-6-3b = []
rdfox-7-0 = []


143 changes: 113 additions & 30 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ lazy_static! {
static ref RDFOX_VERSION_EXPECTED: &'static str =
option_env!("RDFOX_VERSION_EXPECTED").unwrap_or("6.3b");
}
#[cfg(not(any(feature = "rdfox-6-2", feature = "rdfox-6-3a", feature = "rdfox-6-3b")))]
#[cfg(feature = "rdfox-7-0")]
lazy_static! {
static ref RDFOX_VERSION_EXPECTED: &'static str =
option_env!("RDFOX_VERSION_EXPECTED").unwrap_or("7.0");
}
#[cfg(not(any(feature = "rdfox-6-2", feature = "rdfox-6-3a", feature = "rdfox-6-3b", feature = "rdfox-7-0")))]
compile_error!("You have to at least specify one of the rdfox-X-Y version number features");

fn rdfox_download_url() -> String {
Expand Down Expand Up @@ -177,7 +182,7 @@ fn rdfox_lib_dir() -> PathBuf {
env::var("OUT_DIR").unwrap(),
rdfox_archive_name()
)
.into()
.into()
}

fn rdfox_header_dir() -> PathBuf {
Expand All @@ -186,17 +191,17 @@ fn rdfox_header_dir() -> PathBuf {
env::var("OUT_DIR").unwrap(),
rdfox_archive_name()
)
.into()
.into()
}

fn download_rdfox() -> Result<PathBuf, curl::Error> {
println!("cargo:rerun-if-env-changed=RDFOX_DOWNLOAD_HOST");
println!("cargo:rerun-if-env-changed=RDFOX_VERSION_EXPECTED");

println!(
"cargo:warning=\"TARGET: {}\"",
env::var("TARGET").ok().unwrap_or("not set".to_string())
);
// println!(
// "cargo:warning=\"TARGET: {}\"",
// env::var("TARGET").ok().unwrap_or("not set".to_string())
// );

let mut curl = curl::easy::Easy::new();
let url = rdfox_download_url();
Expand All @@ -209,11 +214,11 @@ fn download_rdfox() -> Result<PathBuf, curl::Error> {
file_name.to_str().unwrap()
)
}) {
println!(
"cargo:warning=\"RDFox has already been downloaded: {}\"",
file_name.to_str().unwrap()
);
return Ok(file_name)
// println!(
// "cargo:warning=\"RDFox has already been downloaded: {}\"",
// file_name.to_str().unwrap()
// );
return Ok(file_name);
}

curl.url(url.as_str())?;
Expand Down Expand Up @@ -285,10 +290,13 @@ fn unzip_rdfox(zip_file: PathBuf, archive_name: String) -> PathBuf {
}

fn set_clang_path<S: Into<String>>(path: Option<S>) -> Option<(PathBuf, PathBuf)> {
if path.is_none() {
return None;
}
path.as_ref()?;
let path = PathBuf::from(path.unwrap().into());
if !path.exists() {
return None
return None;
}
let path = std::fs::canonicalize(path).unwrap();

Expand All @@ -306,10 +314,13 @@ fn set_clang_path<S: Into<String>>(path: Option<S>) -> Option<(PathBuf, PathBuf)
}

fn set_llvm_config_path<S: Into<String>>(path: Option<S>) -> Option<(PathBuf, PathBuf)> {
if path.is_none() {
return None;
}
path.as_ref()?;
let path = PathBuf::from(path.unwrap().into());
if !path.exists() {
return None
return None;
}
let path = std::fs::canonicalize(path).unwrap();

Expand All @@ -327,27 +338,26 @@ fn set_llvm_config_path<S: Into<String>>(path: Option<S>) -> Option<(PathBuf, Pa
}

fn add_clang_path() {
let (_, clang_path) = set_clang_path(option_env!("LIBCLANG_PATH"))
let (clang_path, _clang_bin) = set_clang_path(option_env!("LIBCLANG_PATH"))
.or_else(|| set_clang_path(option_env!("HOMEBREW_PREFIX")))
.or_else(|| set_clang_path(Some("/opt/homebrew")))
.unwrap_or_else(|| panic!("Could not find the clang path"));

let clang_path = clang_path.to_str().unwrap();

println!("cargo:warning=clang path is {}", clang_path);
println!("cargo:rustc-env=LIBCLANG_PATH={:}", clang_path);
println!("cargo:rustc-link-search=native={:}", clang_path);
println!("cargo:rustc-link-search=native={:}/lib", clang_path);
println!(
"cargo:rustc-link-search=native={:}/c++",
"cargo:rustc-link-search=native={:}/lib/c++",
clang_path
);
}

fn add_llvm_path() {
let (_, llvm_config_bin) = set_llvm_config_path(option_env!("LLVM_CONFIG_PATH"))
.or_else(|| set_llvm_config_path(option_env!("LLVM_PATH")))
.or_else(|| set_llvm_config_path(Some("/opt/homebrew/bin")))
.or_else(|| set_llvm_config_path(Some("/usr/local/opt/llvm")))
.or_else(|| set_llvm_config_path(check_llvm_via_brew()))
.or_else(|| set_llvm_config_path(Some("/usr/local/opt/llvm")))
.or_else(|| set_llvm_config_path(Some("/usr/bin")))
.unwrap_or_else(|| panic!("Could not find the LLVM path"));

Expand All @@ -369,12 +379,36 @@ fn add_llvm_path() {
String::from_utf8(llvm_config_path).expect("`llvm-config --prefix` output must be UTF-8");
let llvm_config_path = llvm_config_path.trim();

println!("cargo:warning=llvm config path is {llvm_config_path}");
println!("cargo:rustc-env=LLVM_CONFIG_PATH={llvm_config_path}");
}

#[cfg(any(target_os = "macos", target_os = "linux"))]
fn check_homebrew_prefix() -> Option<PathBuf> {
if let Some(path) = option_env!("HOMEBREW_PREFIX") {
if let Ok(path) = PathBuf::from(path).canonicalize() {
return Some(path);
}
}
if let Ok(path) = PathBuf::from("/opt/homebrew").canonicalize() {
return Some(path);
}
if let Ok(output) = Command::new("brew").args(["--prefix"]).output() {
let homebrew_prefix =
String::from_utf8(output.stdout).expect("`brew --prefix` output must be UTF-8");
if let Ok(path) = PathBuf::try_from(homebrew_prefix) {
return Some(path);
}
}
None
}

#[cfg(any(target_os = "macos", target_os = "linux"))]
fn check_llvm_via_brew() -> Option<String> {
if let Some(homebrew_prefix) = check_homebrew_prefix() {
if homebrew_prefix.join("opt/llvm").exists() {
return Some(homebrew_prefix.join("opt/llvm").to_str().unwrap().to_owned());
}
}
if let Ok(output) = Command::new("brew").args(["--prefix", "llvm"]).output() {
let llvm_path =
String::from_utf8(output.stdout).expect("`brew --prefix llvm` output must be UTF-8");
Expand All @@ -384,6 +418,53 @@ fn check_llvm_via_brew() -> Option<String> {
}
}

#[cfg(not(feature = "rdfox-dylib"))]
fn check_lib_iconv() -> Option<String> {
if let Some(homebrew_path) = check_homebrew_prefix() {
if let Ok(path) = homebrew_path.join("opt/libiconv/lib/").canonicalize() {
if let Some(path_str) = path.to_str() {
println!(
"cargo:rustc-link-lib=static:+whole-archive,-bundle,+verbatim={path_str}/libiconv.a"
);
println!("cargo:rustc-link-search=native={path_str}");
return Some(path_str.to_owned());
}
println!("cargo:warning=libiconv path is not valid: {:?}", path);
}
}
println!("cargo:warning=libiconv not found");
None
}

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
fn check_llvm_via_brew() -> Option<String> { None }

#[cfg(not(feature = "rdfox-dylib"))]
fn check_cpp() {
if let Some(homebrew_path) = check_homebrew_prefix() {
if let Ok(path) = homebrew_path.join("opt/llvm/c++/libc++.a").canonicalize() {
if let Some(path_str) = path.to_str() {
println!(
"cargo:rustc-link-lib=static:+whole-archive,-bundle,+verbatim={path_str}"
);
} else {
println!("cargo:warning=libc++ path is not valid: {:?}", path);
}
}
if let Ok(path) = homebrew_path.join("opt/llvm/c++/libc++abi.a").canonicalize() {
if let Some(path_str) = path.to_str() {
println!(
"cargo:rustc-link-lib=static:+whole-archive,-bundle,+verbatim={path_str}"
);
} else {
println!("cargo:warning=libc++abi path is not valid: {:?}", path);
}
}
} else {
println!("cargo:warning=homebrew not found");
}
}

#[cfg(not(any(target_os = "macos", target_os = "linux")))]
fn check_llvm_via_brew() -> Option<String> { None }

Expand Down Expand Up @@ -438,13 +519,14 @@ fn main() {
#[cfg(not(feature = "rdfox-dylib"))]
{
println!("cargo:rustc-link-lib=static:+whole-archive,-bundle=RDFox-static");
println!(
"cargo:rustc-link-lib=static:+whole-archive,-bundle,+verbatim=/usr/local/Cellar/\
libiconv/1.17/lib/libiconv.a"
);
println!("cargo:rustc-link-lib=static:+whole-archive,-bundle=c++");
println!("cargo:rustc-link-lib=static:+whole-archive,-bundle=c++abi");
println!("cargo:rustc-link-search=native:/usr/local/Cellar/libiconv/1.17/lib");
check_cpp();
check_lib_iconv();
}

if let Ok(_fmt_config) = PathBuf::from(RUSTFMT_CONFIG).canonicalize() {
// println!("cargo:warning=Found rustfmt configuration file: {}", _fmt_config.to_str().unwrap());
} else {
println!("cargo:warning=Could not find rustfmt configuration file: {}", RUSTFMT_CONFIG);
}

let mut codegen_config = CodegenConfig::all();
Expand All @@ -468,8 +550,9 @@ fn main() {
non_exhaustive: false,
})
.translate_enum_integer_types(true)
// .clang_arg(r"-xc++")
// .clang_arg(r"-std=c++20")
.clang_arg(r"-xc++")
.clang_arg(r"-std=c++14")
.clang_arg(r"-static-libstdc++")
.clang_arg(format!("-I{}", rdfox_header_dir().to_str().unwrap()))
.clang_arg("-v")
// .clang_arg(r"-Wl,--whole-archive RDFox-static -Wl,--no-whole-archive")
Expand Down
2 changes: 1 addition & 1 deletion src/data_store_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl DataStoreConnection {
writer: W,
statement: &'a Statement,
mime_type: &'static Mime,
base_iri: Option<Iri>,
base_iri: Option<&Iri>,
) -> Result<Streamer<'a, W>, RDFStoreError>
where
W: 'a + Write,
Expand Down
8 changes: 4 additions & 4 deletions src/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
CPrefixes_newDefaultPrefixes,
},
},
iref::Iri,
iref::iri::Iri,
rdf_store_rs::{
consts::{LOG_TARGET_DATABASE, PREFIX_OWL, PREFIX_RDF, PREFIX_RDFS, PREFIX_XSD},
Class,
Expand Down Expand Up @@ -149,10 +149,10 @@ impl Namespaces {
}
}

pub fn declare<'a, Base: Into<Iri<'a>>>(
pub fn declare(
self: &Arc<Self>,
name: &str,
iri: Base,
iri: &iref::iri::Iri,
) -> Result<NamespaceDeclareResult, RDFStoreError> {
self.declare_namespace(&Namespace::declare(name, iri))
}
Expand Down Expand Up @@ -199,7 +199,7 @@ pub struct NamespacesBuilder {
impl<'a> NamespacesBuilder {
pub fn default_builder() -> Self { NamespacesBuilder { namespaces: Vec::new() } }

pub fn declare_with_name_and_iri<Base: Into<Iri<'a>>>(mut self, name: &str, iri: Base) -> Self {
pub fn declare_with_name_and_iri(mut self, name: &str, iri: &Iri) -> Self {
self.namespaces.push(Namespace::declare(name, iri));
self
}
Expand Down
Loading

0 comments on commit 9b6fdd2

Please sign in to comment.