Skip to content

Instantly share code, notes, and snippets.

@sax
Last active May 2, 2024 01:16
Show Gist options
  • Save sax/9c4b3b841d15ed62fde135da28b783fa to your computer and use it in GitHub Desktop.
Save sax/9c4b3b841d15ed62fde135da28b783fa to your computer and use it in GitHub Desktop.
swift-bridge nightly warning
Cargo.lock
Generated
target/

An example project to demonstrate a warning produced by swift-bridge when compiled on nightly rust:

  • rust version: rustc 1.80.0-nightly (f705de596 2024-04-30)
$ cargo +nightly build -Zbuild-std --target aarch64-apple-darwin

   Compiling swift-bridge-example v0.0.0 (/.../workspace/gist/9c4b3b841d15ed62fde135da28b783fa)
error: field `0` is never read
 --> lib.rs:6:16
  |
3 | #[swift_bridge::bridge]
  | ----------------------- field in this variant
...
6 |     pub struct BridgedError {
  |                ^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> lib.rs:1:38
  |
1 | #![cfg_attr(feature = "strict", deny(warnings))]
  |                                      ^^^^^^^^
  = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
6 |     pub struct () {
  |                ~~

error: could not compile `swift-bridge-example` (lib) due to 1 previous error
const XCODE_CONFIGURATION_ENV: &str = "CONFIGURATION";
fn main() {
let out_dir = "Generated";
let bridges = vec!["lib.rs"];
let watched_paths = vec!["lib.rs", "Cargo.toml"];
for path in &watched_paths {
println!("cargo::rerun-if-changed={}", path);
}
println!("cargo::rerun-if-env-changed={}", XCODE_CONFIGURATION_ENV);
swift_bridge_build::parse_bridges(bridges)
.write_all_concatenated(out_dir, env!("CARGO_PKG_NAME"));
}
[package]
name = "swift-bridge-example"
build = "build.rs"
[build-dependencies]
swift-bridge-build = "0.1"
[dependencies]
swift-bridge = { version = "0.1", features = ["async"] }
[features]
default = ["strict"] # Treat warnings as a build error.
strict = []
[lib]
crate-type = ["staticlib"]
path = "lib.rs"
#![cfg_attr(feature = "strict", deny(warnings))]
#[swift_bridge::bridge]
mod ffi {
#[swift_bridge(swift_repr = "struct")]
pub struct BridgedError {
inner: String,
}
extern "Rust" {
type RustApp;
#[swift_bridge(init)]
fn new() -> RustApp;
fn do_thing(&self) -> Result<(), BridgedError>;
}
}
pub type CrateResult<T> = Result<T, ffi::BridgedError>;
// // // RustApp
pub struct RustApp;
impl RustApp {
pub(crate) fn new() -> Self {
Self
}
pub(crate) fn do_thing(&self) -> CrateResult<()> {
Ok(())
}
}
// // // BridgedError
impl std::error::Error for ffi::BridgedError {}
impl std::fmt::Debug for ffi::BridgedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}
impl std::fmt::Display for ffi::BridgedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment