Skip to content

Commit 4c1d2ef

Browse files
authored
Fix feature configuration using cargo-hack (#545)
This PR fixes certain feature combinations identified by [cargo-hack](https://github.com/taiki-e/cargo-hack). - `cargo hack build --each-feature --all-targets` - `cargo hack clippy --each-feature --all-targets -- -D warnings`
2 parents 4a64868 + f011222 commit 4c1d2ef

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

crates/duckdb/src/vtab/arrow.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ mod test {
11691169
},
11701170
buffer::{OffsetBuffer, ScalarBuffer},
11711171
datatypes::{
1172-
i256, ArrowPrimitiveType, ByteArrayType, DataType, DurationSecondType, Field, Fields, IntervalDayTimeType,
1172+
i256, ArrowPrimitiveType, ByteArrayType, DataType, DurationSecondType, Field, IntervalDayTimeType,
11731173
IntervalMonthDayNanoType, IntervalYearMonthType, Schema,
11741174
},
11751175
record_batch::RecordBatch,
@@ -1220,6 +1220,8 @@ mod test {
12201220
#[test]
12211221
#[cfg(feature = "appender-arrow")]
12221222
fn test_append_struct() -> Result<(), Box<dyn Error>> {
1223+
use arrow::datatypes::Fields;
1224+
12231225
let db = Connection::open_in_memory()?;
12241226
db.execute_batch("CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER))")?;
12251227
{
@@ -1257,6 +1259,8 @@ mod test {
12571259
#[test]
12581260
#[cfg(feature = "appender-arrow")]
12591261
fn test_append_struct_contains_null() -> Result<(), Box<dyn Error>> {
1262+
use arrow::datatypes::Fields;
1263+
12601264
let db = Connection::open_in_memory()?;
12611265
db.execute_batch("CREATE TABLE t1 (s STRUCT(v VARCHAR, i INTEGER))")?;
12621266
{

crates/libduckdb-sys/build.rs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,18 @@ mod build_linked {
296296
// Try to use pkg-config to determine link commands
297297
let pkgconfig_path = Path::new(&dir).join("pkgconfig");
298298
env::set_var("PKG_CONFIG_PATH", pkgconfig_path);
299-
if pkg_config::Config::new().probe(link_lib).is_err() {
299+
300+
#[cfg(feature = "pkg-config")]
301+
let lib_found = pkg_config::Config::new().probe(link_lib).is_ok();
302+
#[cfg(not(feature = "pkg-config"))]
303+
let lib_found = false;
304+
305+
if !lib_found {
300306
// Otherwise just emit the bare minimum link commands.
301307
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
302308
println!("cargo:rustc-link-search={dir}");
303309
}
310+
304311
return HeaderLocation::FromEnvironment;
305312
}
306313

@@ -309,39 +316,50 @@ mod build_linked {
309316
}
310317

311318
// See if pkg-config can do everything for us.
312-
match pkg_config::Config::new().print_system_libs(false).probe(link_lib) {
313-
Ok(mut lib) => {
314-
if let Some(header) = lib.include_paths.pop() {
315-
HeaderLocation::FromPath(header.to_string_lossy().into())
316-
} else {
319+
#[cfg(feature = "pkg-config")]
320+
{
321+
match pkg_config::Config::new().print_system_libs(false).probe(link_lib) {
322+
Ok(mut lib) => {
323+
if let Some(header) = lib.include_paths.pop() {
324+
HeaderLocation::FromPath(header.to_string_lossy().into())
325+
} else {
326+
HeaderLocation::Wrapper
327+
}
328+
}
329+
Err(_) => {
330+
// No env var set and pkg-config couldn't help; just output the link-lib
331+
// request and hope that the library exists on the system paths. We used to
332+
// output /usr/lib explicitly, but that can introduce other linking problems;
333+
// see https://github.com/rusqlite/rusqlite/issues/207.
334+
if !cfg!(feature = "loadable-extension") {
335+
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
336+
}
317337
HeaderLocation::Wrapper
318338
}
319339
}
320-
Err(_) => {
321-
// No env var set and pkg-config couldn't help; just output the link-lib
322-
// request and hope that the library exists on the system paths. We used to
323-
// output /usr/lib explicitly, but that can introduce other linking problems;
324-
// see https://github.com/rusqlite/rusqlite/issues/207.
325-
if !cfg!(feature = "loadable-extension") {
326-
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
327-
}
328-
HeaderLocation::Wrapper
340+
}
341+
#[cfg(not(feature = "pkg-config"))]
342+
{
343+
// No pkg-config available; just output the link-lib request and hope
344+
// that the library exists on the system paths.
345+
if !cfg!(feature = "loadable-extension") {
346+
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
329347
}
348+
HeaderLocation::Wrapper
330349
}
331350
}
332351

333352
fn try_vcpkg() -> Option<HeaderLocation> {
334-
if cfg!(feature = "vcpkg") && is_compiler("msvc") {
353+
#[cfg(feature = "vcpkg")]
354+
if is_compiler("msvc") {
335355
// See if vcpkg can find it.
336356
if let Ok(mut lib) = vcpkg::Config::new().probe(lib_name()) {
337357
if let Some(header) = lib.include_paths.pop() {
338358
return Some(HeaderLocation::FromPath(header.to_string_lossy().into()));
339359
}
340360
}
341-
None
342-
} else {
343-
None
344361
}
362+
None
345363
}
346364
}
347365

@@ -485,12 +503,11 @@ mod bindings {
485503
.write(Box::new(&mut output))
486504
.expect("could not write output of bindgen");
487505

506+
#[allow(unused_mut)]
488507
let mut output = String::from_utf8(output).expect("bindgen output was not UTF-8?!");
489508

490509
#[cfg(feature = "loadable-extension")]
491-
{
492-
generate_functions(&mut output);
493-
}
510+
generate_functions(&mut output);
494511

495512
let mut file = OpenOptions::new()
496513
.write(true)

0 commit comments

Comments
 (0)