From f7a635ba7f33e699fac05f1c58f5568494046cf4 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 22 Feb 2023 14:21:50 +0900 Subject: [PATCH] Fix native build --- Cargo.lock | 8 ++++---- Cargo.toml | 10 +++------- build.rs | 10 +--------- src/bin.rs | 17 +++++++++++++++++ src/lib.rs | 4 ++-- src/main.rs | 31 ------------------------------- 6 files changed, 27 insertions(+), 53 deletions(-) create mode 100644 src/bin.rs delete mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 91bff41..712ae33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,18 +247,18 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "serde" -version = "1.0.137" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 920779b..aeb771b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,15 +14,11 @@ serde = { version = "1.0.101", features = ["derive"] } [build-dependencies] bindgen = "0.64" -[features] -default = [] -no_link_libs = [] - [lib] name = "ld45_lib" -crate-type = ["staticlib"] -required-features = ["no_link_libs"] +path = "src/lib.rs" +crate-type = ["rlib", "staticlib"] [[bin]] name = "ld45_bin" -path = "src/main.rs" +path = "src/bin.rs" diff --git a/build.rs b/build.rs index e16c200..1bb9aed 100644 --- a/build.rs +++ b/build.rs @@ -3,17 +3,9 @@ extern crate bindgen; use std::env; use std::path::PathBuf; -#[cfg(not(feature = "no_link_libs"))] -fn linking_libs() { +fn main() { println!("cargo:rustc-link-lib=raylib"); println!("cargo:rustc-link-lib=OpenGL"); -} - -#[cfg(feature = "no_link_libs")] -fn linking_libs() {} - -fn main() { - linking_libs(); println!("cargo:rerun-if-changed=raylib/raylib.h"); let bindings = bindgen::Builder::default() diff --git a/src/bin.rs b/src/bin.rs new file mode 100644 index 0000000..cdbbb6f --- /dev/null +++ b/src/bin.rs @@ -0,0 +1,17 @@ +use ld45_lib::agnostic_interface; + +fn will_close() -> bool { + unsafe { agnostic_interface::raylib_impl::ffi::WindowShouldClose() } +} + +fn main() { + let state_ptr = ld45_lib::ld45_initialize(); + + while !will_close() { + ld45_lib::ld45_iterate(state_ptr); + } + + unsafe { + drop(Box::from_raw(state_ptr as *mut ld45_lib::WasmState)); + } +} diff --git a/src/lib.rs b/src/lib.rs index 0331a45..7e6484f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -mod agnostic_interface; +pub mod agnostic_interface; mod faux_quicksilver; mod original_impl; mod shaders; @@ -7,7 +7,7 @@ use agnostic_interface::raylib_impl::RaylibGame; use faux_quicksilver::Window; use original_impl::GameState; -struct WasmState { +pub struct WasmState { pub window: Window, pub game_state: GameState, } diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 6241b62..0000000 --- a/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -use agnostic_interface::raylib_impl::RaylibGame; -use faux_quicksilver::Window; -use original_impl::GameState; - -mod agnostic_interface; -mod faux_quicksilver; -mod original_impl; -mod shaders; - -fn will_close() -> bool { - unsafe { agnostic_interface::raylib_impl::ffi::WindowShouldClose() } -} - -fn main() { - // TODO - //run::( - // "One And All - a Ludum Dare 45 compo entry", - // Vector::new(800, 600), - // Settings::default(), - //); - - let game_interface = RaylibGame::new_boxed(800, 600); - let mut window = Window::new(game_interface); - let mut game_state = GameState::new(&mut window).unwrap(); - - while !will_close() { - window.update_music().unwrap(); - game_state.update(&mut window).unwrap(); - game_state.draw(&mut window).unwrap(); - } -}