Conditional compilation of typings in preparation

This commit is contained in:
Jeremy Wall 2022-02-19 16:22:05 -05:00
parent 1797963dd0
commit 4bfd04b048
3 changed files with 38 additions and 13 deletions

View File

@ -3,6 +3,11 @@ name = "web"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[features]
ssr = []
web = []
default = ["web"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

View File

@ -15,7 +15,7 @@ use std::collections::BTreeMap;
use crate::{console_debug, console_error, console_log}; use crate::{console_debug, console_error, console_log};
use reqwasm::http::{self}; use reqwasm::http;
use sycamore::prelude::*; use sycamore::prelude::*;
use web_sys::{window, Storage}; use web_sys::{window, Storage};

View File

@ -31,10 +31,14 @@ extern "C" {
macro_rules! console_log { macro_rules! console_log {
// Note that this is using the `log` function imported above during // Note that this is using the `log` function imported above during
// `bare_bones` // `bare_bones`
($($t:tt)*) => {{ ($($t:tt)*) => {
use crate::typings::log; if cfg!(feature="web") {
(log(&format_args!($($t)*).to_string())) use crate::typings::log;
}} log(&format_args!($($t)*).to_string());
} else if cfg!(feature="ssr") {
println!($($t)*);
}
}
} }
#[macro_export] #[macro_export]
@ -42,27 +46,43 @@ macro_rules! console_debug {
// Note that this is using the `log` function imported above during // Note that this is using the `log` function imported above during
// `bare_bones` // `bare_bones`
($($t:tt)*) => {{ ($($t:tt)*) => {{
use crate::typings::debug; if cfg!(feature="web") {
(debug(&format_args!($($t)*).to_string())) use crate::typings::debug;
debug(&format_args!($($t)*).to_string());
} else if cfg!(feature="ssr") {
print!("DEBUG: ");
println!($($t)*);
}
}} }}
} }
#[macro_export] #[macro_export]
macro_rules! console_error { macro_rules! console_error {
// Note that this is using the `log` function imported above during // Note that this is using the `error` function imported above during
// `bare_bones` // `bare_bones`
($($t:tt)*) => {{ ($($t:tt)*) => {{
use crate::typings::error; if cfg!(feature="web")
(error(&format_args!($($t)*).to_string())) {
use crate::typings::error;
error(&format_args!($($t)*).to_string());
}else if cfg!(feature="ssr") {
print!("ERROR: ");
println!($($t)*);
};
}} }}
} }
#[macro_export] #[macro_export]
macro_rules! console_warn { macro_rules! console_warn {
// Note that this is using the `log` function imported above during // Note that this is using the `warn` function imported above during
// `bare_bones` // `bare_bones`
($($t:tt)*) => {{ ($($t:tt)*) => {{
use crate::typings::warn; if cfg!("web") {
(warn(&format_args!($($t)*).to_string())) use crate::typings::warn;
(warn(&format_args!($($t)*).to_string()))
} else if cfg!(feature="ssr") {
print!("WARN: ");
(println!($($t)*))
}
}} }}
} }