Skip to content

Commit 309556d

Browse files
author
Charles Samuels
committed
libduckdb-sys: include duckdb (1.1.1) as a submodule
- Build it directly with cmake, having a cargo feature for each extension. - parquet is documented as being required, so the extension is always enabled and the feature is ignored (for backwards compatibility) - the "delta" extension doesn't build, so there's no feature for it
1 parent f887844 commit 309556d

File tree

6 files changed

+54
-116
lines changed

6 files changed

+54
-116
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,3 @@ Cargo.lock
2727

2828
*.db
2929

30-
crates/libduckdb-sys/duckdb-sources/
31-
crates/libduckdb-sys/duckdb/
32-
crates/libduckdb-sys/._duckdb

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = crates/libduckdb-sys/duckdb-sources
33
url = https://github.com/duckdb/duckdb
44
update = none
5+
[submodule "crates/libduckdb-sys/duckdb"]
6+
path = crates/libduckdb-sys/duckdb
7+
url = https://github.com/duckdb/duckdb

crates/libduckdb-sys/Cargo.toml

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libduckdb-sys"
3-
version = "1.0.0"
3+
version = "1.1.0+libduckdb.1.1.1"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -17,25 +17,25 @@ exclude = ["duckdb-sources"]
1717

1818
[features]
1919
default = ["vcpkg", "pkg-config"]
20-
bundled = ["cc"]
20+
bundled = ["cmake"]
2121
buildtime_bindgen = ["bindgen", "pkg-config", "vcpkg"]
22-
json = ["bundled"]
23-
parquet = ["bundled"]
24-
extensions-full = ["json", "parquet"]
22+
parquet = ["bundled"] # ignored
23+
extensions-full = ["autocomplete","httpfs","tpcds","fts","icu", "json","parquet"]
2524
winduckdb = []
25+
autocomplete = ["bundled"]
26+
httpfs = ["bundled"]
27+
tpcds = ["bundled"]
28+
fts = ["bundled"]
29+
icu = ["bundled"]
30+
json = ["bundled"]
2631

2732
[dependencies]
2833

2934
[build-dependencies]
30-
autocfg = { workspace = true }
3135
bindgen = { workspace = true, features = ["runtime"], optional = true }
32-
flate2 = { workspace = true }
3336
pkg-config = { workspace = true, optional = true }
34-
cc = { workspace = true, features = ["parallel"], optional = true }
3537
vcpkg = { workspace = true, optional = true }
36-
serde = { workspace = true, features = ["derive"] }
37-
serde_json = { workspace = true }
38-
tar = { workspace = true }
38+
cmake = { version = "0.1.51", optional = true }
3939

4040
[dev-dependencies]
4141
arrow = { workspace = true, features = ["ffi"] }

crates/libduckdb-sys/build.rs

+39-102
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
let out_path = Path::new(&out_dir).join("bindgen.rs");
2626
#[cfg(feature = "bundled")]
2727
{
28-
build_bundled::main(&out_dir, &out_path);
28+
build_bundled::main(&out_path);
2929
}
3030
#[cfg(not(feature = "bundled"))]
3131
{
@@ -35,56 +35,9 @@ fn main() {
3535

3636
#[cfg(feature = "bundled")]
3737
mod build_bundled {
38-
use std::{
39-
collections::{HashMap, HashSet},
40-
path::Path,
41-
};
38+
use std::path::Path;
4239

43-
use crate::win_target;
44-
45-
#[derive(serde::Deserialize)]
46-
struct Sources {
47-
cpp_files: HashSet<String>,
48-
include_dirs: HashSet<String>,
49-
}
50-
51-
#[derive(serde::Deserialize)]
52-
struct Manifest {
53-
base: Sources,
54-
55-
#[allow(unused)]
56-
extensions: HashMap<String, Sources>,
57-
}
58-
59-
#[allow(unused)]
60-
fn add_extension(
61-
cfg: &mut cc::Build,
62-
manifest: &Manifest,
63-
extension: &str,
64-
cpp_files: &mut HashSet<String>,
65-
include_dirs: &mut HashSet<String>,
66-
) {
67-
cpp_files.extend(manifest.extensions.get(extension).unwrap().cpp_files.clone());
68-
include_dirs.extend(manifest.extensions.get(extension).unwrap().include_dirs.clone());
69-
cfg.define(
70-
&format!("DUCKDB_EXTENSION_{}_LINKED", extension.to_uppercase()),
71-
Some("1"),
72-
);
73-
}
74-
75-
fn untar_archive(out_dir: &str) {
76-
let path = "duckdb.tar.gz";
77-
78-
let tar_gz = std::fs::File::open(path).expect("archive file");
79-
let tar = flate2::read::GzDecoder::new(tar_gz);
80-
let mut archive = tar::Archive::new(tar);
81-
archive.unpack(out_dir).expect("archive");
82-
}
83-
84-
pub fn main(out_dir: &str, out_path: &Path) {
85-
let lib_name = super::lib_name();
86-
87-
untar_archive(out_dir);
40+
pub fn main(out_path: &Path) {
8841

8942
if !cfg!(feature = "bundled") {
9043
// This is just a sanity check, the top level `main` should ensure this.
@@ -94,7 +47,7 @@ mod build_bundled {
9447
#[cfg(feature = "buildtime_bindgen")]
9548
{
9649
use super::{bindings, HeaderLocation};
97-
let header = HeaderLocation::FromPath(format!("{out_dir}/{lib_name}/src/include/duckdb.h"));
50+
let header = HeaderLocation::FromPath(format!("duckdb/src/include/duckdb.h"));
9851
bindings::write_to_out_dir(header, out_path);
9952
}
10053
#[cfg(not(feature = "buildtime_bindgen"))]
@@ -103,64 +56,48 @@ mod build_bundled {
10356
fs::copy("src/bindgen_bundled_version.rs", out_path).expect("Could not copy bindings to output directory");
10457
}
10558

106-
let manifest_file = std::fs::File::open(format!("{out_dir}/{lib_name}/manifest.json")).expect("manifest file");
107-
let manifest: Manifest = serde_json::from_reader(manifest_file).expect("reading manifest file");
108-
109-
let mut cpp_files = HashSet::new();
110-
let mut include_dirs = HashSet::new();
111-
112-
cpp_files.extend(manifest.base.cpp_files.clone());
113-
// otherwise clippy will remove the clone here...
114-
// https://github.com/rust-lang/rust-clippy/issues/9011
115-
#[allow(clippy::all)]
116-
include_dirs.extend(manifest.base.include_dirs.clone());
117-
118-
let mut cfg = cc::Build::new();
119-
120-
#[cfg(feature = "parquet")]
121-
add_extension(&mut cfg, &manifest, "parquet", &mut cpp_files, &mut include_dirs);
122-
123-
#[cfg(feature = "json")]
124-
add_extension(&mut cfg, &manifest, "json", &mut cpp_files, &mut include_dirs);
125-
126-
// duckdb/tools/pythonpkg/setup.py
127-
cfg.define("DUCKDB_EXTENSION_AUTOINSTALL_DEFAULT", "1");
128-
cfg.define("DUCKDB_EXTENSION_AUTOLOAD_DEFAULT", "1");
129-
130-
// Since the manifest controls the set of files, we require it to be changed to know whether
131-
// to rebuild the project
132-
println!("cargo:rerun-if-changed={out_dir}/{lib_name}/manifest.json");
133-
// Make sure to rebuild the project if tar file changed
134-
println!("cargo:rerun-if-changed=duckdb.tar.gz");
135-
136-
cfg.include(lib_name);
137-
cfg.includes(include_dirs.iter().map(|dir| format!("{out_dir}/{lib_name}/{dir}")));
138-
139-
for f in cpp_files.into_iter().map(|file| format!("{out_dir}/{file}")) {
140-
cfg.file(f);
141-
}
142-
143-
cfg.cpp(true)
144-
.flag_if_supported("-std=c++11")
145-
.flag_if_supported("-stdlib=libc++")
146-
.flag_if_supported("-stdlib=libstdc++")
147-
.flag_if_supported("/bigobj")
148-
.warnings(false)
149-
.flag_if_supported("-w");
150-
151-
if win_target() {
152-
cfg.define("DUCKDB_BUILD_LIBRARY", None);
153-
}
154-
cfg.compile(lib_name);
155-
156-
println!("cargo:lib_dir={out_dir}");
59+
// jemalloc is not built; use the rust jemallocator crate
60+
#[allow(unused_mut)]
61+
let mut extensions = "parquet".to_string();
62+
#[cfg(feature="autocomplete")] { extensions += ";autocomplete"; }
63+
#[cfg(feature="httpfs")] { println!("cargo:rustc-link-lib=static=httpfs_extension"); extensions += ";httpfs"; }
64+
#[cfg(feature="tpcds")] { println!("cargo:rustc-link-lib=static=tpcds_extension"); extensions += ";tpcds"; }
65+
#[cfg(feature="fts")] { println!("cargo:rustc-link-lib=static=fts_extension"); extensions += ";fts"; }
66+
#[cfg(feature="icu")] { println!("cargo:rustc-link-lib=static=icu_extension"); extensions += ";icu"; }
67+
#[cfg(feature="json")] { println!("cargo:rustc-link-lib=static=json_extension"); extensions += ";json"; }
68+
69+
let dst = cmake::Config::new("duckdb")
70+
.define("ENABLE_EXTENSION_AUTOLOADING", "1")
71+
.define("ENABLE_EXTENSION_AUTOINSTALL", "1")
72+
.define("BUILD_JEMALLOC", "0")
73+
.define("BUILD_EXTENSIONS",&extensions)
74+
.define("BUILD_UNITTESTS", "0")
75+
.profile("Release")
76+
.build();
77+
println!("cargo:rustc-link-search=native={}/lib", dst.display());
78+
println!("cargo:rustc-link-lib=static=duckdb_fastpforlib");
79+
println!("cargo:rustc-link-lib=static=duckdb_fmt");
80+
println!("cargo:rustc-link-lib=static=duckdb_fsst");
81+
println!("cargo:rustc-link-lib=static=duckdb_hyperloglog");
82+
println!("cargo:rustc-link-lib=static=duckdb_mbedtls");
83+
println!("cargo:rustc-link-lib=static=duckdb_miniz");
84+
println!("cargo:rustc-link-lib=static=duckdb_pg_query");
85+
println!("cargo:rustc-link-lib=static=duckdb_re2");
86+
println!("cargo:rustc-link-lib=static=duckdb_skiplistlib");
87+
println!("cargo:rustc-link-lib=static=duckdb_static");
88+
println!("cargo:rustc-link-lib=static=duckdb_utf8proc");
89+
println!("cargo:rustc-link-lib=static=duckdb_yyjson");
90+
println!("cargo:rustc-link-lib=static=parquet_extension");
91+
92+
println!("cargo:rustc-link-lib=stdc++");
15793
}
15894
}
15995

16096
fn env_prefix() -> &'static str {
16197
"DUCKDB"
16298
}
16399

100+
#[allow(dead_code)]
164101
fn lib_name() -> &'static str {
165102
"duckdb"
166103
}

crates/libduckdb-sys/duckdb

Submodule duckdb added at af39bd0

crates/libduckdb-sys/duckdb.tar.gz

-3.94 MB
Binary file not shown.

0 commit comments

Comments
 (0)