Moved to a workspace for future crates

This commit is contained in:
2025-10-30 18:55:42 +01:00
parent 61f5e276da
commit 641a93906d
29 changed files with 48 additions and 65 deletions

2
Cargo.lock generated
View File

@@ -48,7 +48,7 @@ dependencies = [
]
[[package]]
name = "oc2r-rust"
name = "oc2r-core"
version = "0.1.0"
dependencies = [
"libc",

View File

@@ -1,7 +1,14 @@
[package]
name = "oc2r-rust"
version = "0.1.0"
[workspace]
resolver = "3"
members = ["crates/*"]
[workspace.package]
authors = ["Christopher Head <chead@chead.ca>"]
edition = "2024"
repository = "https://git.jika.li/jika/oc2r-rust"
license = "GPL-3.0-only"
keywords = ["minecraft", "opencomputers"]
categories = ["games"]
[workspace.lints.clippy]
enum_glob_use = "deny"
@@ -13,10 +20,7 @@ unwrap_used = "deny"
strip = true
opt-level = "s"
lto = true
codegen-units = 1
[dependencies]
miniserde = "0.1"
miniserde-enum = {git = "https://git.jika.li/Jika/miniserde_enum"}
# miniserde-enum = {git = "https://github.com/yuki0iq/miniserde-enum"}
libc = "0.2"
[workspace.dependencies]
oc2r-core = { path = "crates/oc2r-core" }

View File

@@ -1,41 +1,39 @@
OC2R Rust Client
================
# OC2R Rust Client
Thin, synchronous access to the OC2R high-level API from Rust. The crate mirrors
the stock Lua helpers (`devices.lua`) so you can list devices, invoke methods,
the stock Lua helpers (`devices.lua`, `robot.lua`) so you can list devices, invoke methods,
subscribe to events, and work with typed wrappers for common peripherals.
Documentation
-------------
## Documentation
See [`docs/index.md`](docs/index.md) for the full guide and
[`docs/wrappers.md`](docs/wrappers.md) for device-by-device examples.
Examples
--------
## Development
We ship three binaries that mirror Lua scripts:
The crate targets rust nightly for some size optimisations and relies on `miniserde` and `libc`.
- `examples/list-devices.rs`
- `examples/invoke-method.rs`
- `examples/redstone.rs`
- `examples/redstone-events.rs`
To ease developpemnt we use [cross-rs](https://github.com/cross-rs/cross),
but you can install all toolchain component or your local computer and replace cross with cargo.
By default the option "-Zfmt-debug=none" is set meaning all debug print (:?) are off. If you can disable this option at any time.
# Compilation
Simply `cross clippy --all-targets` to compile all examples
## Examples
Examples of how to use the crate are in the `examples` directory.
Build them with:
```bash
# Install instructions: https://github.com/cross-rs/cross#installation
cross build --release --example list-devices
cross build --release --example example-names
```
Copy the resulting binaries from
`target/<triple>/release/examples/` into Minux (an Import/Export card works
well), then execute them inside the VM.
well), mark them as executable and then execute them inside the VM.
Development
-----------
The crate targets stable Rust 1.74+ and relies on `miniserde` and `libc`. Use
`cross clippy --all-targets` before submitting changes. CI scripts are still in
flight; for now the `cross build` and `cross clippy` invocations exercised in
the examples are the reference.

View File

@@ -0,0 +1,9 @@
[package]
name = "oc2r-core"
version = "0.1.0"
edition = "2024"
[dependencies]
miniserde = "0.1"
miniserde-enum = {git = "https://git.jika.li/Jika/miniserde_enum"}
libc = "0.2"

View File

@@ -6,13 +6,13 @@ wrappers that mirror `devices.lua`.
## Getting Started
1. Install `cross` (one-time):
1. Install [cross](https://github.com/cross-rs/cross):
```bash
cargo install cross --git https://github.com/cross-rs/cross
```
2. Compile your binary for Minux:
```bash
cross build --release --bin your-app
cross build --release
```
3. Copy `target/<triple>/release/your-app` onto the Import/Export card and drop
it inside the OC2R VM (e.g. `/usr/bin/your-app`).

View File

@@ -1,6 +1,6 @@
// Build with: cross build --release --example invoke-method
use oc2r_rust::{DEFAULT_DEVICE_PATH, DeviceBus, Result};
use oc2r_core::{DEFAULT_DEVICE_PATH, DeviceBus, Result};
fn main() -> Result<()> {
let mut bus = DeviceBus::connect(DEFAULT_DEVICE_PATH)?;

View File

@@ -1,6 +1,6 @@
// Build with: cross build --release --example list-devices
use oc2r_rust::{DEFAULT_DEVICE_PATH, DeviceBus, Result};
use oc2r_core::{DEFAULT_DEVICE_PATH, DeviceBus, Result};
fn main() -> Result<()> {
let mut bus = DeviceBus::connect(DEFAULT_DEVICE_PATH)?;

View File

@@ -1,4 +1,4 @@
use oc2r_rust::{DEFAULT_DEVICE_PATH, DeviceBus, EventLoop, JsonValueExt, Redstone, Result};
use oc2r_core::{DEFAULT_DEVICE_PATH, DeviceBus, EventLoop, JsonValueExt, Redstone, Result};
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;

View File

@@ -1,6 +1,6 @@
// Build with: cross build --release --example redstone
use oc2r_rust::{DEFAULT_DEVICE_PATH, DeviceBus, Redstone, Result, Side};
use oc2r_core::{DEFAULT_DEVICE_PATH, DeviceBus, Redstone, Result, Side};
use std::env;
use std::str::FromStr;

View File

@@ -1,28 +0,0 @@
use oc2r_rust::{DEFAULT_DEVICE_PATH, DeviceBus, DeviceEntry, Result};
fn main() -> Result<()> {
println!("Opening {DEFAULT_DEVICE_PATH}");
let mut bus = DeviceBus::connect(DEFAULT_DEVICE_PATH)?;
let drained = bus.flush()?;
println!("Drained {drained} stale bytes.");
println!("Listing devices…");
let devices = bus.list()?;
for device in devices {
print_device(&device);
}
Ok(())
}
fn print_device(device: &DeviceEntry) {
println!("deviceId: {}", device.device_id);
if !device.type_names.is_empty() {
println!(" typeNames: {}", device.type_names.join(", "));
}
if let Some(desc) = &device.description {
println!(" description: {desc}");
}
println!("--------");
}