Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d0150f5
update rust edition & make clippy changes
nakajimayoshi Mar 22, 2025
f03dea8
revert units type change
nakajimayoshi Mar 22, 2025
a06d59e
undo clippy change
nakajimayoshi Mar 22, 2025
2510afd
undo weird formatting changes
nakajimayoshi Mar 22, 2025
df9fb4a
undo stupid formats
nakajimayoshi Mar 22, 2025
a9a5aec
update bindgen
nakajimayoshi Mar 22, 2025
73ddd41
undo changes to build.rs
nakajimayoshi Mar 22, 2025
4770e1c
use clippy recommended format
nakajimayoshi Mar 23, 2025
a651f37
fix cargo clippy errors
nakajimayoshi Jul 19, 2025
03c4eb6
run cargo fmt
nakajimayoshi Jul 19, 2025
4cc30f2
update bindgen to 0.72
nakajimayoshi Jul 19, 2025
577850b
Merge remote-tracking branch 'origin/main' into rust-2024
nakajimayoshi Jul 20, 2025
aed96cb
wrap wrap_executor() in unsafe block
nakajimayoshi Jul 20, 2025
2a84e0b
cargo fmt
nakajimayoshi Jul 20, 2025
a2cf1f2
use cargo workspace resolver 2024 edition
nakajimayoshi Jul 21, 2025
1a5489b
allow unsafe in msfs-derive macros
nakajimayoshi Jul 21, 2025
3b1fd7c
mute clippy warning for wrap_executor()
nakajimayoshi Jul 21, 2025
ed866e3
add #[allow(unsafe_attr_outside_unsafe)] to derive no_mangle macros
nakajimayoshi Jul 21, 2025
86ca07d
unsafe(no_mangle)
nakajimayoshi Jul 21, 2025
e372107
mark module ffis as unsafe
nakajimayoshi Jul 21, 2025
8bc277d
no mangle
nakajimayoshi Jul 21, 2025
d6d03bd
merge origin/main
nakajimayoshi Sep 13, 2025
d37228c
remove clippy directive
nakajimayoshi Sep 13, 2025
a600075
re-add clippy unsafe-ignore macro
nakajimayoshi Sep 13, 2025
4b91623
remove unncessary unsafes
nakajimayoshi Sep 13, 2025
020bcdd
Update msfs_derive/src/lib.rs
nakajimayoshi Sep 13, 2025
fa9e6eb
Update msfs_derive/src/lib.rs
nakajimayoshi Sep 13, 2025
cb3b1d6
Update lib.rs
nakajimayoshi Sep 18, 2025
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "3"
members = [
"msfs",
"msfs_sdk",
Expand Down
8 changes: 4 additions & 4 deletions msfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "msfs"
version = "0.1.0"
version = "0.2.0"
authors = ["snek"]
edition = "2018"
edition = "2024"
description = "Rust bindings for the MSFS SDK"
license = "MIT"

[dependencies]
msfs_derive = { path = "../msfs_derive", version = "0.2.0" }
msfs_derive = { path = "../msfs_derive", version = "0.3.0" }
futures = "0.3"
libc = "0.2"

[build-dependencies]
bindgen = "0.72"
msfs_sdk = { path = "../msfs_sdk", version = "0.1.0" }
msfs_sdk = { path = "../msfs_sdk", version = "0.2.0" }
cc = "1.0"
6 changes: 5 additions & 1 deletion msfs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ fn main() {

// build nanovg wrapper
if wasm {
std::env::set_var("AR", "llvm-ar");
unsafe {
std::env::set_var("AR", "llvm-ar");
}

cc::Build::new()
.compiler("clang")
.flag(format!("--sysroot={msfs_sdk}/WASM/wasi-sysroot"))
Expand Down Expand Up @@ -39,6 +42,7 @@ fn main() {
.blocklist_function("nvgStrokePaint")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.rustified_enum("SIMCONNECT_EXCEPTION")
.layout_tests(false)
.impl_debug(false)
// `opaque_type` added to avoid alignment errors. These alignment errors are caused
// because virtual methods are not well supported in rust-bindgen.
Expand Down
6 changes: 1 addition & 5 deletions msfs/src/commbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ impl<'a> CommBusEvent<'a> {
this.callback.as_ref() as *const _ as *mut _,
)
};
if res {
Some(this)
} else {
None
}
if res { Some(this) } else { None }
}

extern "C" fn c_callback(args: *const ffi::c_char, size: ffi::c_uint, ctx: *mut ffi::c_void) {
Expand Down
2 changes: 1 addition & 1 deletion msfs/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::{channel::mpsc, Future};
use futures::{Future, channel::mpsc};
use std::pin::Pin;
use std::task::Poll;

Expand Down
6 changes: 1 addition & 5 deletions msfs/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ impl SimVarF64 for f64 {

impl SimVarF64 for bool {
fn to(self) -> f64 {
if self {
1.0
} else {
0.0
}
if self { 1.0 } else { 0.0 }
}

fn from(v: f64) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion msfs/src/msfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum MSFSEvent<'a> {
/// Only call this function if you know what you're doing! This function is only safe
/// to be used if one is **absolutely sure** that there is only 1 reference to it at all times!
pub unsafe fn wrap_executor<E, T>(executor: *mut E, handle: impl FnOnce(&mut E) -> T) -> T {
handle(&mut *executor)
unsafe { handle(&mut *executor) }
}

/// Gauge
Expand Down
3 changes: 2 additions & 1 deletion msfs/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deref_nullptr)]
#![allow(unsafe_op_in_unsafe_fn)]
include!(concat!(env!("OUT_DIR"), "/msfs-sys.rs"));

// https://github.com/rustwasm/team/issues/291
extern "C" {
unsafe extern "C" {
pub fn nvgStrokeColor(ctx: *mut NVGcontext, color: *const NVGcolor);
pub fn nvgStrokePaint(ctx: *mut NVGcontext, paint: *const NVGpaint);
pub fn nvgFillColor(ctx: *mut NVGcontext, color: *const NVGcolor);
Expand Down
4 changes: 2 additions & 2 deletions msfs_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "msfs_derive"
version = "0.2.0"
version = "0.3.0"
authors = ["snek"]
edition = "2018"
edition = "2024"
description = "This crate provides macros for MSFS"
license = "MIT"

Expand Down
23 changes: 9 additions & 14 deletions msfs_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use proc_macro::TokenStream;
use quote::{format_ident, quote};
use std::collections::HashMap;
use syn::{
Expr, Ident, ItemFn, ItemStruct, Lit, Meta, Token, Type,
parse::{Parse, ParseStream, Result as SynResult},
parse_macro_input, Expr, Ident, ItemFn, ItemStruct, Lit, Meta, Token, Type,
parse_macro_input,
};

/// Declare a standalone module.
Expand Down Expand Up @@ -40,18 +41,16 @@ pub fn standalone_module(_args: TokenStream, item: TokenStream) -> TokenStream {
},
};

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn module_init() {
unsafe {
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_init());
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn module_deinit() {
unsafe {
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_deinit());
}
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_deinit());
}
};

Expand Down Expand Up @@ -125,27 +124,23 @@ pub fn gauge(args: TokenStream, item: TokenStream) -> TokenStream {
};

#[doc(hidden)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn #extern_gauge_name(
ctx: ::msfs::sys::FsContext,
service_id: std::os::raw::c_int,
p_data: *mut std::os::raw::c_void,
) -> bool {
unsafe {
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_gauge(ctx, service_id, p_data))
}
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_gauge(ctx, service_id, p_data))
}

#[doc(hidden)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn #extern_mouse_name(
fx: std::os::raw::c_float,
fy: std::os::raw::c_float,
i_flags: std::os::raw::c_uint,
) {
unsafe {
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_mouse(fx, fy, i_flags));
}
::msfs::wrap_executor(&raw mut #executor_name, |e| e.handle_mouse(fx, fy, i_flags));
}
};

Expand Down
4 changes: 2 additions & 2 deletions msfs_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "msfs_sdk"
version = "0.1.0"
version = "0.2.0"
authors = ["snek"]
edition = "2018"
edition = "2024"
description = "Crate to find MSFS SDK"
license = "MIT"

Expand Down
4 changes: 3 additions & 1 deletion msfs_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ pub fn calculate_msfs_sdk_path() -> Result<String, &'static str> {
return Ok(p.to_string());
}
}
Err("Could not locate MSFS SDK. Make sure you have it installed or try setting the MSFS_SDK env var.")
Err(
"Could not locate MSFS SDK. Make sure you have it installed or try setting the MSFS_SDK env var.",
)
}