Skip to content

Commit

Permalink
move codegen to separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilken committed Aug 10, 2020
1 parent 25ff572 commit 588c6eb
Show file tree
Hide file tree
Showing 225 changed files with 255 additions and 247 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ uuid = {version = "0.8", features = ["v4", "serde"]}

[dev-dependencies]
env_logger = "0.7"

[workspace]
members = ["codegen"]
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ For a full list of the predefined characteristics, services and accessories, see
Creating a simple lightbulb accessory and starting the IP server:

```rust
use std::net::{IpAddr, SocketAddr};

use hap::{
accessory::{lightbulb::LightbulbAccessory, AccessoryCategory, AccessoryInformation},
server::{IpServer, Server},
Expand All @@ -62,28 +60,13 @@ use hap::{

#[tokio::main]
async fn main() {
let current_ipv4 = || -> Option<IpAddr> {
for iface in pnet::datalink::interfaces() {
for ip_network in iface.ips {
if ip_network.is_ipv4() {
let ip = ip_network.ip();
if !ip.is_loopback() {
return Some(ip);
}
}
}
}
None
};

let lightbulb = LightbulbAccessory::new(1, AccessoryInformation {
name: "Acme Lightbulb".into(),
..Default::default()
})
.unwrap();

let config = Config {
socket_addr: SocketAddr::new(current_ipv4().unwrap(), 32000),
pin: Pin::new([1, 1, 1, 2, 2, 3, 3, 3]).unwrap(),
name: "Acme Lightbulb".into(),
device_id: MacAddress::new([10, 20, 30, 40, 50, 60]),
Expand Down Expand Up @@ -162,6 +145,12 @@ lightbulb.lightbulb.on.set_value(Value::Bool(true)).await.unwrap();
- [ ] Video Doorbell Accessory
- [ ] BLE Transport

## Development

Codegen is handled by the `codegen` crate in the workspace. Generated files are checked in. To run the code generation, do:

cargo run --package hap-codegen

## License

HAP is licensed under either of
Expand Down
18 changes: 18 additions & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
authors = ["Elias Wilken <[email protected]>"]
description = "Rust implementation of the Apple HomeKit Accessory Protocol (HAP)"
documentation = "https://docs.rs/hap"
edition = "2018"
keywords = ["apple", "homekit"]
license = "MIT/Apache-2.0"
name = "hap-codegen"
publish = false
readme = "README.md"
repository = "https://github.com/ewilken/hap-rs"
version = "0.1.0-pre.2"

[dependencies]
handlebars = "2.0"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
uuid = {version = "0.8", features = ["v4", "serde"]}
File renamed without changes.
18 changes: 8 additions & 10 deletions build.rs → codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ fn pascal_case_helper(
Ok(())
}

static CATEGORIES: &'static str = "// this file is auto-generated by build.rs\n
static CATEGORIES: &'static str = "// this file is auto-generated by hap-codegen\n
use serde::{Deserialize, Serialize};
/// HAP Accessory category.
Expand All @@ -381,7 +381,7 @@ pub enum AccessoryCategory {
}
";

static HAP_TYPE: &'static str = "// this file is auto-generated by build.rs\n
static HAP_TYPE: &'static str = "// this file is auto-generated by hap-codegen\n
use serde::ser::{Serialize, Serializer};
/// HAP Service and Characteristic type representation.
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Serialize for HapType {
}
";

static CHARACTERISTIC: &'static str = "// this file is auto-generated by build.rs\n
static CHARACTERISTIC: &'static str = "// this file is auto-generated by hap-codegen\n
use async_trait::async_trait;
use serde::Serialize;
use serde_json::json;
Expand Down Expand Up @@ -542,11 +542,11 @@ impl AsyncCharacteristicCallbacks<{{type characteristic.Format}}> for {{pascal_c
}
";

static CHARACTERISTIC_MOD: &'static str = "// this file is auto-generated by build.rs
static CHARACTERISTIC_MOD: &'static str = "// this file is auto-generated by hap-codegen
{{#each characteristics as |c|}}\npub mod {{c}};{{/each}}
";

static SERVICE: &'static str = "// this file is auto-generated by build.rs\n
static SERVICE: &'static str = "// this file is auto-generated by hap-codegen\n
use serde::ser::{Serialize, SerializeStruct, Serializer};
use crate::{
Expand Down Expand Up @@ -685,11 +685,11 @@ impl Serialize for {{pascal_case service.Name}}Service {
}
";

static SERVICE_MOD: &'static str = "// this file is auto-generated by build.rs
static SERVICE_MOD: &'static str = "// this file is auto-generated by hap-codegen
{{#each services as |s|}}\npub mod {{s}};{{/each}}
";

static ACCESSORY: &'static str = "// this file is auto-generated by build.rs\n
static ACCESSORY: &'static str = "// this file is auto-generated by hap-codegen\n
use serde::ser::{Serialize, SerializeStruct, Serializer};
use crate::{
Expand Down Expand Up @@ -779,7 +779,7 @@ impl Serialize for {{pascal_case service.Name}}Accessory {
}
";

static ACCESSORY_MOD: &'static str = "// this file is auto-generated by build.rs
static ACCESSORY_MOD: &'static str = "// this file is auto-generated by hap-codegen
{{#each accessories as |a|}}\npub mod {{a}};{{/each}}
";

Expand Down Expand Up @@ -841,8 +841,6 @@ static ACCESSORY_MOD: &'static str = "// this file is auto-generated by build.rs
// ";

fn main() {
println!("cargo:rerun-if-changed=gen/default.json");

let metadata_file = File::open("gen/default.json").unwrap();
let mut metadata_ex = MetadataEx {
metadata: serde_json::from_reader(&metadata_file).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion src/accessory/category.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/air_purifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/air_quality_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/carbon_dioxide_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/carbon_monoxide_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/contact_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/door.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/fan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/fan_v2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/garage_door_opener.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/heater_cooler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/humidifier_dehumidifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/humidity_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/leak_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/light_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/lightbulb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

pub mod air_purifier;
pub mod air_quality_sensor;
Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/motion_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/occupancy_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/outlet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/security_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/smoke_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/stateless_programmable_switch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/switch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/temperature_sensor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/thermostat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/valve.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/accessory/generated/window_covering.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use serde::ser::{Serialize, SerializeStruct, Serializer};

Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/accessory_flags.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/active.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/active_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/administrator_only_access.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/air_particulate_density.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/air_particulate_size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/air_quality.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/audio_feedback.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/battery_level.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/brightness.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/carbon_dioxide_detected.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/characteristic/generated/carbon_dioxide_level.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// this file is auto-generated by build.rs
// this file is auto-generated by hap-codegen

use async_trait::async_trait;
use serde::Serialize;
Expand Down
Loading

0 comments on commit 588c6eb

Please sign in to comment.