Skip to content

Commit

Permalink
feat: added utilities library
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwine36 committed Aug 16, 2024
1 parent 1c5a0b7 commit a9d4581
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Pipeline"
on:
push:
branches:
- "main"
pull_request:
jobs:
ci:
name: "CI"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
- uses: "moonrepo/setup-toolchain@v0"
- run: "moon ci"
2 changes: 1 addition & 1 deletion .moon/tasks/tag-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tasks:
local: true

test:
command: 'cargo nextest run --workspace'
command: 'cargo test --workspace'
inputs:
- '@group(cargo)'
- '@group(sources)'
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/sample-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ wasm-bindgen = {workspace = true}
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }
js-sys = {workspace = true}
utilities = { path = "../utilities" }

[dev-dependencies]
wasm-bindgen-test = {workspace = true}
Expand Down
7 changes: 1 addition & 6 deletions crates/sample-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod utils;

use utilities::console_log;
use wasm_bindgen::prelude::*;
pub mod functions;
// use functions::game_of_life::*;
Expand All @@ -23,12 +24,6 @@ extern "C" {
fn log_many(a: &str, b: &str);
}

macro_rules! console_log {
// Note that this is using the `log` function imported above during
// `bare_bones`
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}

#[wasm_bindgen]
pub fn greet() {
console_log!("Hello fibbers");
Expand Down
12 changes: 12 additions & 0 deletions crates/utilities/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "utilities"
version = "0.1.0"
authors = ["Alex Wine <alexwine36@gmail.com>"]
edition = "2021"


[dependencies]
wasm-bindgen = {workspace = true}

[dev-dependencies]
wasm-bindgen-test = {workspace = true}
3 changes: 3 additions & 0 deletions crates/utilities/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type: "library"

tags: ['rust']
2 changes: 2 additions & 0 deletions crates/utilities/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// #[cfg(target_arch = "wasm32")]
pub mod web;
26 changes: 26 additions & 0 deletions crates/utilities/src/web.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
// Use `js_namespace` here to bind `console.log(..)` instead of just
// `log(..)`
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);

// The `console.log` is quite polymorphic, so we can bind it with multiple
// signatures. Note that we need to use `js_name` to ensure we always call
// `log` in JS.
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_u32(a: u32);

// Multiple arguments too!
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_many(a: &str, b: &str);
}

#[macro_export]
macro_rules! console_log {

($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
Empty file added crates/utilities/tests/lib.rs
Empty file.
5 changes: 5 additions & 0 deletions templates/rust-package/template.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# https://moonrepo.dev/docs/config/template
$schema: 'https://moonrepo.dev/schemas/template.json'

destination: 'crates/[name | kebab_case]'

title: 'rust-package'
description: |
A simple rust package
Expand Down

0 comments on commit a9d4581

Please sign in to comment.