Skip to content

Commit

Permalink
Add explicit static link type, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoll committed Dec 14, 2023
1 parent c4a3127 commit ccbf787
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::env;
use std::path::PathBuf;
use std::{env, path::PathBuf};

fn main() {
let dst = cmake::build("open62541");

println!("cargo:rustc-link-search={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=open62541");
println!("cargo:rustc-link-lib=static=open62541");

let input = env::current_dir().unwrap().join("wrapper.h");

Expand All @@ -16,21 +15,26 @@ fn main() {
.allowlist_type("(__)?UA_.*")
.allowlist_var("(__)?UA_.*")
.clang_arg(format!("-I{}", dst.join("include").display()))
// Do not derive `Copy` because most of the data types are not copy-safe (they own memory by
// pointers and need to be cloned manually to duplicate that memory).
.derive_copy(false)
.derive_debug(true)
// The auto-derived comments are not particularly useful because they often do not match the
// declaration they belong to.
.generate_comments(false)
.header(input.to_string_lossy())
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// We may use `core` instead of `std`. This might be useful for `no_std` environments.
.use_core()
// Wrap static functions. These are used in several places for inline helpers and we want to
// preserve those in the generated bindings. This outputs `extern.c` which we compile below.
.wrap_static_fns(true)
.generate()
.expect("Unable to generate bindings");
.expect("should generate `Bindings` instance");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
.expect("should write `bindings.rs`");

let ext_name = "open62541-extern";
let statc_path = env::current_dir().unwrap().join("wrapper.c");
Expand All @@ -43,7 +47,8 @@ fn main() {
.include(input.parent().unwrap())
// Disable warnings for `open62541`. Not much we can do anyway.
.warnings(false)
// Explicitly disable warning (seems to be enabled by default).
// Explicitly disable deprecation warnings (seem to be enabled even when other warnings have
// been disabled above).
.flag_if_supported("-Wno-deprecated-declarations")
.flag_if_supported("-Wno-deprecated")
.compile(ext_name);
Expand Down

0 comments on commit ccbf787

Please sign in to comment.