Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

radar-console-utils

Utility library written in Rust and compiled to WebAssembly via wasm-bindgen, designed to be consumed from Node.js.

Prerequisites

Tool Tested version Notes
Rust (rustc/cargo) 1.96.0 edition 2024 (MSRV 1.85)
wasm32-unknown-unknown target required to compile to WASM
wasm-pack 0.15.0 generates the JS-consumable package
Node.js ≥ 16 to use the generated package

Installing the Rust prerequisites:

# Rust toolchain (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# WebAssembly compilation target
rustup target add wasm32-unknown-unknown

# wasm-pack
cargo install wasm-pack

Generating the wasm

wasm-pack is the tool that produces the JS-consumable WebAssembly package: it compiles the crate to wasm, runs wasm-bindgen to emit the JS/TypeScript glue, and optimizes the binary with wasm-opt.

The key flag is --target nodejs, which emits CommonJS glue (require/module.exports) rather than bundler- or browser-oriented output.

# Production build (optimized) — this is the command to generate the package
wasm-pack build --target nodejs --release

# Development build (faster, unoptimized)
wasm-pack build --target nodejs --dev

Note: plain cargo build --target wasm32-unknown-unknown only compiles the crate to a raw .wasm — it does not run wasm-bindgen/wasm-opt and does not produce the consumable pkg/. Use it only as a quick compile check.

The output is written to the pkg/ directory (git-ignored):

pkg/
├── package.json                     # npm manifest of the generated package
├── radar_console_utils.js           # JS glue code (entrypoint, "main")
├── radar_console_utils.d.ts         # TypeScript types
├── radar_console_utils_bg.wasm      # WebAssembly binary
└── radar_console_utils_bg.wasm.d.ts # wasm module types

Usage in Node.js

const utils = require("./pkg/radar_console_utils.js");

// Top-level function
console.log(utils.getApiVersion()); // "1.0.0"

// MathUtils (static methods)
console.log(utils.MathUtils.linear2dB(100));    // 20
console.log(utils.MathUtils.metersByBin(0, 1)); // 10.463...

const power = utils.MathUtils.computeRawPowerFast(
  Float64Array.from([1, 2, 3]),
  Float64Array.from([4, 5, 6]),
);
console.log(power); // Float64Array [17, 29, 45]

// DataUtils (static methods)
console.log(utils.DataUtils.testComunicazione());

Exported API

  • getApiVersion(): string
  • MathUtils.linear2dB(power: number): number
  • MathUtils.metersByBin(bin: number, miles: number): number
  • MathUtils.getTargetColor(levels: Float64Array, value: number, minVisibleColorLevel: number): number
  • MathUtils.computeRawPowerFast(iData: Float64Array, qData: Float64Array): Float64Array
  • DataUtils.testComunicazione(): string

Development

# Quick compile check only (does NOT generate pkg/ — see the note above)
cargo build --target wasm32-unknown-unknown

# Lint
cargo clippy --target wasm32-unknown-unknown --all-targets

Note: since this is a WASM-oriented cdylib, the only exposed functions are those annotated with #[wasm_bindgen] and declared in src/lib.rs (currently the math_utils and data_utils modules).

About

radar-rust-utils

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages