-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(cargo): Add cbindgen support via
build.rs
- Loading branch information
Showing
3 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2022 Jan Holthuis <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy | ||
// of the MPL was not distributed with this file, You can obtain one at | ||
// http://mozilla.org/MPL/2.0/. | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
let output_file = target_dir() | ||
.join("include") | ||
.join("rekordcrate.h") | ||
.display() | ||
.to_string(); | ||
|
||
cbindgen::Builder::new() | ||
.with_crate(crate_dir) | ||
.generate() | ||
.expect("Unable to generate bindings") | ||
.write_to_file(&output_file); | ||
} | ||
|
||
/// Find the location of the `target/` directory. Note that this may be | ||
/// overridden by `cmake`, so we also need to check the `CARGO_TARGET_DIR` | ||
/// variable. | ||
fn target_dir() -> PathBuf { | ||
if let Ok(target) = env::var("CARGO_TARGET_DIR") { | ||
PathBuf::from(target) | ||
} else { | ||
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("target") | ||
} | ||
} |