Skip to content
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

Add C FFI [WIP] #86

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 198 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 5 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
[package]
name = "rekordcrate"
version = "0.1.1"
authors = ["Jan Holthuis <[email protected]>"]
description = "Library for parsing Pioneer Rekordbox device exports"
readme = "README.md"
repository = "https://github.com/Holzhaus/rekordcrate"
license = "MPL-2.0"
keywords = ["rekordbox", "dj", "export", "database", "parser"]
categories = ["parser-implementations"]
edition = "2021"
exclude = [".*"]
[workspace]

[dependencies]
binrw = "0.10"
modular-bitfield = "0.11"
crc16 = "0.4"
clap = { version = "4.0.10", features = ["derive"], optional = true }

[build-dependencies]
glob = "0.3"

[features]
default = ["cli"]
cli = ["dep:clap"]

[[bin]]
name = "rekordcrate"
required-features = ["cli"]
members = [
"rekordcrate",
"rekordcrate-ffi",
]
21 changes: 21 additions & 0 deletions rekordcrate-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "rekordcrate-ffi"
version = "0.1.1"
authors = ["Jan Holthuis <[email protected]>"]
description = "C bindings for rekordcrate"
readme = "README.md"
repository = "https://github.com/Holzhaus/rekordcrate"
license = "MPL-2.0"
keywords = ["rekordbox", "dj", "export", "database", "parser"]
categories = ["parser-implementations"]
edition = "2021"
exclude = [".*"]

[dependencies]
rekordcrate = { version = "0.1.1", path = "../rekordcrate" }

[build-dependencies]
cbindgen = "0.24.3"

[lib]
crate_type = ["cdylib"]
36 changes: 36 additions & 0 deletions rekordcrate-ffi/build.rs
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")
}
}
Loading