Skip to content
Snippets Groups Projects
Verified Commit 1f7e57e8 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: support for WASM engine version

Uses built package to print dependencies.
parent 90cf4126
No related branches found
No related tags found
No related merge requests found
Pipeline #2221 failed
...@@ -9,3 +9,4 @@ Cargo.lock ...@@ -9,3 +9,4 @@ Cargo.lock
/frontends/*/target /frontends/*/target
/src/gen/build.rs /src/gen/build.rs
/src/gen/_build.rs
...@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
* * Support for WASM engine version printing
### Changed ### Changed
......
...@@ -25,6 +25,7 @@ wasm-bindgen = { version = "0.2", optional = true } ...@@ -25,6 +25,7 @@ wasm-bindgen = { version = "0.2", optional = true }
[build-dependencies] [build-dependencies]
chrono = "0.4" chrono = "0.4"
regex = "1" regex = "1"
built = "0.5"
[profile.release] [profile.release]
debug = false debug = false
......
#![allow(clippy::uninlined_format_args)] #![allow(clippy::uninlined_format_args)]
/// Build script (https://doc.rust-lang.org/cargo/reference/build-scripts.html) //! Build script (https://doc.rust-lang.org/cargo/reference/build-scripts.html)
/// This script is executed as the first step in the compilation process. //! This script is executed as the first step in the compilation process.
/// Here we export metadata constants to a `constants/generated.rs` file which is then //! Here we export metadata constants to a `constants/generated.rs` file which is then
/// imported and used by the remaining crate. //! imported and used by the remaining crate.
/// //!
/// # Examples //! # Examples
/// //!
/// In C you can use the preprocessor macro `__DATE__` to save the compilation date like: //! In C you can use the preprocessor macro `__DATE__` to save the compilation date like:
/// //!
/// ```c //! ```c
/// #define COMPILATION_DATE __DATE__ //! #define COMPILATION_DATE __DATE__
/// ``` //! ```
/// //!
/// Rust does not have such preprocessor macros, so we use this script and do: //! Rust does not have such preprocessor macros, so we use this script and do:
/// //!
/// ```rust //! ```rust
/// let now_utc = chrono::Utc::now(); //! let now_utc = chrono::Utc::now();
/// write_str_constant( //! write_str_constant(
/// &mut file, //! &mut file,
/// "COMPILATION_DATE", //! "COMPILATION_DATE",
/// &format!("{}", now_utc.format("%b %d %Y")), //! &format!("{}", now_utc.format("%b %d %Y")),
/// ); //! );
/// ``` //! ```
use built::{write_built_file_with_opts, Options};
use chrono::Utc; use chrono::Utc;
use regex::Regex; use regex::Regex;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
...@@ -32,7 +34,7 @@ use std::process::Command; ...@@ -32,7 +34,7 @@ use std::process::Command;
use std::{env, str}; use std::{env, str};
const BUILD_OUT_FILE: &str = "build.rs"; const BUILD_OUT_FILE: &str = "build.rs";
const SOURCE_DIR: &str = "./src/gen"; const GEN_DIR: &str = "./src/gen";
fn main() { fn main() {
// in case we're running under docs.rs then we must return the control // in case we're running under docs.rs then we must return the control
...@@ -44,7 +46,7 @@ fn main() { ...@@ -44,7 +46,7 @@ fn main() {
// opens the target destination file panicking with a proper message in // opens the target destination file panicking with a proper message in
// case it was not possible to open it (eg: directory inexistent) // case it was not possible to open it (eg: directory inexistent)
let dest_path = Path::new(SOURCE_DIR).join(Path::new(BUILD_OUT_FILE)); let dest_path = Path::new(GEN_DIR).join(Path::new(BUILD_OUT_FILE));
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.truncate(true) .truncate(true)
.write(true) .write(true)
...@@ -52,11 +54,8 @@ fn main() { ...@@ -52,11 +54,8 @@ fn main() {
.open(dest_path) .open(dest_path)
.unwrap_or_else(|_| panic!("Can't open '{}'", BUILD_OUT_FILE)); .unwrap_or_else(|_| panic!("Can't open '{}'", BUILD_OUT_FILE));
let module_doc_string = "//! Global constants, such as compiler version used, features, platform information and others.\n"; writeln!(file, "{}", "//! Global constants, such as compiler version used, features, platform information and others.\n").unwrap();
writeln!(file, "{}", module_doc_string).unwrap(); writeln!(file, "{}", "// @generated\n").unwrap();
let generated_annotation = "// @generated\n";
writeln!(file, "{}", generated_annotation).unwrap();
let now_utc = Utc::now(); let now_utc = Utc::now();
write_str_constant( write_str_constant(
...@@ -152,6 +151,19 @@ fn main() { ...@@ -152,6 +151,19 @@ fn main() {
"PLATFORM_CPU_BITS_INT", "PLATFORM_CPU_BITS_INT",
std::mem::size_of::<usize>() * 8, std::mem::size_of::<usize>() * 8,
); );
let mut options = Options::default();
options.set_cfg(false);
options.set_ci(false);
options.set_compiler(false);
options.set_env(false);
options.set_dependencies(true);
options.set_features(true);
let manifest_path = env::var("CARGO_MANIFEST_DIR").unwrap();
let built_path = Path::new(GEN_DIR).join(Path::new("_build.rs"));
write_built_file_with_opts(&options, manifest_path.as_ref(), &built_path).unwrap();
} }
fn write_constant<T>(file: &mut File, key: &str, val: T) fn write_constant<T>(file: &mut File, key: &str, val: T)
......
...@@ -547,6 +547,11 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -547,6 +547,11 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
}; };
} }
get wasmEngine(): string | null {
if (!this.gameBoy) return null;
return this.gameBoy.get_wasm_engine_ws();
}
get framerate(): number { get framerate(): number {
return this.fps; return this.fps;
} }
......
...@@ -14,7 +14,10 @@ use crate::{ ...@@ -14,7 +14,10 @@ use crate::{
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use crate::ppu::{Palette, Pixel}; use crate::{
gen::dependencies_map,
ppu::{Palette, Pixel},
};
#[cfg(feature = "wasm")] #[cfg(feature = "wasm")]
use std::{ use std::{
...@@ -319,6 +322,17 @@ impl GameBoy { ...@@ -319,6 +322,17 @@ impl GameBoy {
self.ppu().set_palette_colors(&palette); self.ppu().set_palette_colors(&palette);
} }
pub fn get_wasm_engine_ws(&self) -> String {
let dependencies = dependencies_map();
if !dependencies.contains_key("wasm-bindgen") {
return String::from("-");
}
String::from(format!(
"wasm-bindgen/{}",
*dependencies.get("wasm-bindgen").unwrap()
))
}
fn js_to_pixel(value: &JsValue) -> Pixel { fn js_to_pixel(value: &JsValue) -> Pixel {
value value
.as_string() .as_string()
......
...@@ -14,3 +14,8 @@ pub const MAKEFLAGS: &str = "-"; ...@@ -14,3 +14,8 @@ pub const MAKEFLAGS: &str = "-";
pub const FEATURES: [&str; 1] = ["cpu"]; pub const FEATURES: [&str; 1] = ["cpu"];
pub const PLATFORM_CPU_BITS: &str = "64"; pub const PLATFORM_CPU_BITS: &str = "64";
pub const PLATFORM_CPU_BITS_INT: usize = 64; pub const PLATFORM_CPU_BITS_INT: usize = 64;
pub const FEATURES: [&str; 0] = [];
pub const FEATURES_STR: &str = r"";
pub const DEPENDENCIES: [(&str, &str); 0] = [];
pub const DEPENDENCIES_STR: &str = r"";
//! Constants that define the current build and execution environment. //! Constants that define the current build and execution environment.
use std::collections::HashMap;
#[cfg(feature = "gen-mock")] #[cfg(feature = "gen-mock")]
pub mod mock; pub mod mock;
#[cfg(feature = "gen-mock")] #[cfg(feature = "gen-mock")]
...@@ -10,3 +12,11 @@ pub use self::mock::*; ...@@ -10,3 +12,11 @@ pub use self::mock::*;
pub mod build; pub mod build;
#[cfg(not(feature = "gen-mock"))] #[cfg(not(feature = "gen-mock"))]
pub use self::build::*; pub use self::build::*;
#[cfg(not(feature = "gen-mock"))]
pub mod _build;
#[cfg(not(feature = "gen-mock"))]
pub use self::_build::*;
pub fn dependencies_map() -> HashMap<&'static str, &'static str> {
HashMap::from(DEPENDENCIES)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment