Skip to content

Commit

Permalink
bundle extension
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfenjin committed Sep 30, 2023
1 parent 0c37952 commit e3eb0a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 8 additions & 1 deletion libduckdb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ mod build_bundled {
) {
cpp_files.extend(manifest.extensions.get(extension).unwrap().cpp_files.clone());
include_dirs.extend(manifest.extensions.get(extension).unwrap().include_dirs.clone());
cfg.define(&format!("BUILD_{}_EXTENSION", extension.to_uppercase()), Some("1"));
cfg.define(
&format!("DUCKDB_EXTENSION_{}_LINKED", extension.to_uppercase()),
Some("1"),
);
}

fn untar_archive() {
Expand Down Expand Up @@ -131,6 +134,10 @@ mod build_bundled {
#[cfg(feature = "json")]
add_extension(&mut cfg, &manifest, "json", &mut cpp_files, &mut include_dirs);

// duckdb/tools/pythonpkg/setup.py
cfg.define("DUCKDB_EXTENSION_AUTOINSTALL_DEFAULT", "1");
cfg.define("DUCKDB_EXTENSION_AUTOLOAD_DEFAULT", "1");

// Since the manifest controls the set of files, we require it to be changed to know whether
// to rebuild the project
println!("cargo:rerun-if-changed={}/manifest.json", lib_name);
Expand Down
14 changes: 1 addition & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,16 @@ pub enum DefaultNullOrder {

/// duckdb configuration
/// Refer to https://github.com/duckdb/duckdb/blob/master/src/main/config.cpp
#[derive(Default)]
pub struct Config {
config: Option<ffi::duckdb_config>,
}

impl Default for Config {
fn default() -> Self {
Config { config: None }.autoloadable_extension(true).unwrap()
}
}

impl Config {
pub(crate) fn duckdb_config(&self) -> ffi::duckdb_config {
self.config.unwrap_or(std::ptr::null_mut() as ffi::duckdb_config)
}

/// enable autoload extensions
pub fn autoloadable_extension(mut self, enabled: bool) -> Result<Config> {
self.set("autoinstall_known_extensions", &(enabled as i32).to_string())?;
self.set("autoload_known_extensions", &(enabled as i32).to_string())?;
Ok(self)
}

/// Access mode of the database ([AUTOMATIC], READ_ONLY or READ_WRITE)
pub fn access_mode(mut self, mode: AccessMode) -> Result<Config> {
self.set("access_mode", &mode.to_string())?;
Expand Down

0 comments on commit e3eb0a3

Please sign in to comment.