Skip to content

Commit 815eee9

Browse files
committed
issue 1723
1 parent a467d3e commit 815eee9

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

src/lib.rs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,39 +1955,8 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) {
19551955
}
19561956

19571957
impl Bindings {
1958-
/// Generate bindings for the given options.
1959-
pub(crate) fn generate(
1960-
mut options: BindgenOptions,
1961-
) -> Result<Bindings, ()> {
1962-
ensure_libclang_is_loaded();
1963-
1964-
#[cfg(feature = "runtime")]
1965-
debug!(
1966-
"Generating bindings, libclang at {}",
1967-
clang_sys::get_library().unwrap().path().display()
1968-
);
1969-
#[cfg(not(feature = "runtime"))]
1970-
debug!("Generating bindings, libclang linked");
1971-
1972-
options.build();
1973-
1974-
let (effective_target, explicit_target) =
1975-
find_effective_target(&options.clang_args);
1976-
1977-
let is_host_build =
1978-
rust_to_clang_target(HOST_TARGET) == effective_target;
1979-
1980-
// NOTE: The is_host_build check wouldn't be sound normally in some
1981-
// cases if we were to call a binary (if you have a 32-bit clang and are
1982-
// building on a 64-bit system for example). But since we rely on
1983-
// opening libclang.so, it has to be the same architecture and thus the
1984-
// check is fine.
1985-
if !explicit_target && !is_host_build {
1986-
options
1987-
.clang_args
1988-
.insert(0, format!("--target={}", effective_target));
1989-
};
1990-
1958+
/// Common part of generate()
1959+
fn generate_common(options: &mut BindgenOptions) {
19911960
fn detect_include_paths(options: &mut BindgenOptions) {
19921961
if !options.detect_include_paths {
19931962
return;
@@ -2059,8 +2028,43 @@ impl Bindings {
20592028
}
20602029
}
20612030
}
2031+
detect_include_paths(options);
2032+
}
2033+
2034+
/// Generate bindings for the given options.
2035+
pub(crate) fn generate(
2036+
mut options: BindgenOptions,
2037+
) -> Result<Bindings, ()> {
2038+
ensure_libclang_is_loaded();
2039+
2040+
#[cfg(feature = "runtime")]
2041+
debug!(
2042+
"Generating bindings, libclang at {}",
2043+
clang_sys::get_library().unwrap().path().display()
2044+
);
2045+
#[cfg(not(feature = "runtime"))]
2046+
debug!("Generating bindings, libclang linked");
2047+
2048+
options.build();
2049+
2050+
let (effective_target, explicit_target) =
2051+
find_effective_target(&options.clang_args);
2052+
2053+
let is_host_build =
2054+
rust_to_clang_target(HOST_TARGET) == effective_target;
2055+
2056+
// NOTE: The is_host_build check wouldn't be sound normally in some
2057+
// cases if we were to call a binary (if you have a 32-bit clang and are
2058+
// building on a 64-bit system for example). But since we rely on
2059+
// opening libclang.so, it has to be the same architecture and thus the
2060+
// check is fine.
2061+
if !explicit_target && !is_host_build {
2062+
options
2063+
.clang_args
2064+
.insert(0, format!("--target={}", effective_target));
2065+
};
20622066

2063-
detect_include_paths(&mut options);
2067+
Bindings::generate_common(&mut options);
20642068

20652069
#[cfg(unix)]
20662070
fn can_read(perms: &std::fs::Permissions) -> bool {

0 commit comments

Comments
 (0)