(
project_path: &Path,
features: Option<&std::ffi::OsString>,
lint_dir: Option<&Path>,
build_debug: bool,
)
| 24 | } |
| 25 | |
| 26 | pub(crate) fn build_rust( |
| 27 | project_path: &Path, |
| 28 | features: Option<&std::ffi::OsString>, |
| 29 | lint_dir: Option<&Path>, |
| 30 | build_debug: bool, |
| 31 | ) -> anyhow::Result<PathBuf> { |
| 32 | // Make sure that we have the wasm target installed |
| 33 | if !has_wasm32_target() { |
| 34 | if has_rust_up() { |
| 35 | cmd!("rustup", "target", "add", "wasm32-unknown-unknown") |
| 36 | .run() |
| 37 | .context("Failed to install wasm32-unknown-unknown target with rustup")?; |
| 38 | } else { |
| 39 | anyhow::bail!("wasm32-unknown-unknown target is not installed. Please install it."); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if let Some(lint_dir) = lint_dir { |
| 44 | let mut err_count: u32 = 0; |
| 45 | let lint_dir = project_path.join(lint_dir); |
| 46 | for file in walkdir::WalkDir::new(lint_dir).into_iter() { |
| 47 | let file = file?; |
| 48 | let printable_path = file.path().to_str().ok_or(anyhow::anyhow!("path not utf-8"))?; |
| 49 | if file.file_type().is_file() && file.path().extension().is_some_and(|ext| ext == "rs") { |
| 50 | let file = fs::File::open(file.path())?; |
| 51 | for (idx, line) in io::BufReader::new(file).lines().enumerate() { |
| 52 | let line = line?; |
| 53 | let line_number = idx + 1; |
| 54 | for disallowed in &["println!", "print!", "eprintln!", "eprint!", "dbg!"] { |
| 55 | if line.contains(disallowed) { |
| 56 | if err_count == 0 { |
| 57 | eprintln!("\nDetected nonfunctional print statements:\n"); |
| 58 | } |
| 59 | eprintln!("{printable_path}:{line_number}: {line}"); |
| 60 | err_count += 1; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | if err_count > 0 { |
| 67 | eprintln!(); |
| 68 | anyhow::bail!( |
| 69 | "Found {err_count} disallowed print statement(s).\n\ |
| 70 | These will not be printed from SpacetimeDB modules.\n\ |
| 71 | If you need to print something, use the `log` crate\n\ |
| 72 | and the `log::info!` macro instead." |
| 73 | ); |
| 74 | } |
| 75 | } else { |
| 76 | println!( |
| 77 | "Warning: Skipping checks for nonfunctional print statements.\n\ |
| 78 | If you have used builtin macros for printing, such as println!,\n\ |
| 79 | your logs will not show up." |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | let mut args = if let Some(features) = features { |
no test coverage detected
searching dependent graphs…