-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust version on crates.io #741
Comments
Nevermind, I see the way you're doing it in #[link(name = "opendht-c")] |
Nice, tell us if you have any issue with the Rust binding :) Merry Christmas |
Will do! Just playing with automating keeping it up to date using opendht-c and bindgen :-) |
I've created a I presume you're happy with just adding some new functions etc. by hand like you did already the next time you create one? If not, add this to the top of // Ignore Rust's style conventions for our C FFI bindings
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
// Use the include! macro to dump our generated bindings right into our crate's main entry point,
// src/lib.rs:
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); and create a /*
* Copyright (C) 2024 Gavin Henry
* Author: Gavin Henry <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::env;
use std::path::PathBuf;
fn main() {
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// Where do look for things in wrapper.h
.clang_arg("-I../include")
// The input header we would like to generate
// bindings for.
.header("../c/opendht_c.h")
// Pick the things we want to generate bindings for
// .allowlist_function("sentrypeer_config_new|sentrypeer_config_destroy")
// .allowlist_function("sip_message_event_new|sip_message_event_destroy")
// .allowlist_function("sip_log_event")
// Grab everything prefixed with dht_
.allowlist_item("dht_.*")
// Set whether string constants should be generated as &CStr instead of &[u8].
.generate_cstr(true)
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings.rs, so can't use the OpenDHT C lib!");
}
My goal was to get an official Oh, and we could do with a Thanks, |
Merry Christmas all!
I'm in the process of moving SentryPeer to Rust (and writing about it for pragprog.com) and am now looking at my usage of OpenDHT.
I see you have Rust bindings, so I'll play with those and look at how rustls handles bringing in boringssl automatically. I think you expect opendht c libs to be installed before building? I can't see a
build.rs
anyway.Would you mind if I got this on to crates.io? I did the packing for Alpine and Homebrew if you remember?
Thanks,
Gavin.
The text was updated successfully, but these errors were encountered: