use codegen, instead of build.rs, to build header file
This commit is contained in:
2
.cargo/config
Normal file
2
.cargo/config
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[alias]
|
||||||
|
xtask = "run --package xtask --"
|
||||||
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -3035,12 +3035,9 @@ name = "taskchampion-lib"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cbindgen",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"libc",
|
"libc",
|
||||||
"pretty_assertions",
|
|
||||||
"taskchampion",
|
"taskchampion",
|
||||||
"uuid",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3797,6 +3794,14 @@ dependencies = [
|
|||||||
"time 0.1.43",
|
"time 0.1.43",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xtask"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"cbindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroize"
|
name = "zeroize"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ members = [
|
|||||||
"sync-server",
|
"sync-server",
|
||||||
"lib",
|
"lib",
|
||||||
"integration-tests",
|
"integration-tests",
|
||||||
|
"xtask",
|
||||||
]
|
]
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -17,12 +17,18 @@ But, if you just want to get some practice with Rust, we'd be happy to have you.
|
|||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
|
|
||||||
There are four crates here:
|
There are five crates here:
|
||||||
|
|
||||||
* [taskchampion](./taskchampion) - the core of the tool
|
* [taskchampion](./taskchampion) - the core of the tool
|
||||||
* [taskchampion-cli](./cli) - the command-line binary
|
* [taskchampion-cli](./cli) - the command-line binary
|
||||||
* [taskchampion-sync-server](./sync-server) - the server against which `task sync` operates
|
* [taskchampion-sync-server](./sync-server) - the server against which `task sync` operates
|
||||||
* [replica-server-tests](./replica-server-tests) - integration tests covering both _taskchampion-cli_ and _taskchampion-sync-server_
|
* [taskchampion-lib](./lib) - glue code to use _taskchampion_ from C
|
||||||
|
* [integration-tests](./integration-tests) - integration tests covering _taskchampion-cli_, _taskchampion-sync-server_, and _taskchampion-lib_.
|
||||||
|
|
||||||
|
## Code Generation
|
||||||
|
|
||||||
|
The _taskchampion_lib_ crate uses a bit of code generation to create the `lib/taskchampion.h` header file.
|
||||||
|
To regenerate this file, run `cargo xtask codegen`.
|
||||||
|
|
||||||
## Documentation Generation
|
## Documentation Generation
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
name = "taskchampion-lib"
|
name = "taskchampion-lib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "taskchampion"
|
name = "taskchampion"
|
||||||
@@ -17,6 +16,3 @@ anyhow = "1.0"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "1"
|
pretty_assertions = "1"
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
cbindgen = "0.20.0"
|
|
||||||
|
|||||||
26
lib/build.rs
26
lib/build.rs
@@ -1,26 +0,0 @@
|
|||||||
use cbindgen::*;
|
|
||||||
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
||||||
|
|
||||||
Builder::new()
|
|
||||||
.with_crate(crate_dir)
|
|
||||||
.with_config(Config {
|
|
||||||
language: Language::C,
|
|
||||||
cpp_compat: true,
|
|
||||||
sys_includes: vec!["stdbool.h".into(), "stdint.h".into(), "time.h".into()],
|
|
||||||
usize_is_size_t: true,
|
|
||||||
no_includes: true,
|
|
||||||
enumeration: EnumConfig {
|
|
||||||
// this appears to still default to true for C
|
|
||||||
enum_class: false,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.generate()
|
|
||||||
.expect("Unable to generate bindings")
|
|
||||||
.write_to_file("taskchampion.h");
|
|
||||||
}
|
|
||||||
10
xtask/Cargo.toml
Normal file
10
xtask/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "xtask"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
|
cbindgen = "0.20.0"
|
||||||
47
xtask/src/main.rs
Normal file
47
xtask/src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//! This executable defines the `cargo xtask` subcommands.
|
||||||
|
//!
|
||||||
|
//! At the moment it is very simple, but if this grows more subcommands then
|
||||||
|
//! it will be sensible to use `clap` or another similar library.
|
||||||
|
|
||||||
|
use cbindgen::*;
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub fn main() -> anyhow::Result<()> {
|
||||||
|
let arg = env::args().nth(1);
|
||||||
|
match arg.as_ref().map(|arg| arg.as_str()) {
|
||||||
|
Some("codegen") => codegen(),
|
||||||
|
Some(arg) => anyhow::bail!("unknown xtask {}", arg),
|
||||||
|
_ => anyhow::bail!("unknown xtask"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `cargo xtask codegen`
|
||||||
|
///
|
||||||
|
/// This uses cbindgen to generate `lib/taskchampion.h`.
|
||||||
|
fn codegen() -> anyhow::Result<()> {
|
||||||
|
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||||
|
let workspace_dir = manifest_dir.parent().unwrap();
|
||||||
|
let lib_crate_dir = workspace_dir.join("lib");
|
||||||
|
|
||||||
|
Builder::new()
|
||||||
|
.with_crate(&lib_crate_dir)
|
||||||
|
.with_config(Config {
|
||||||
|
language: Language::C,
|
||||||
|
cpp_compat: true,
|
||||||
|
sys_includes: vec!["stdbool.h".into(), "stdint.h".into(), "time.h".into()],
|
||||||
|
usize_is_size_t: true,
|
||||||
|
no_includes: true,
|
||||||
|
enumeration: EnumConfig {
|
||||||
|
// this appears to still default to true for C
|
||||||
|
enum_class: false,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.generate()
|
||||||
|
.expect("Unable to generate bindings")
|
||||||
|
.write_to_file(lib_crate_dir.join("taskchampion.h"));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user