-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #900 from ulrikstrid/ulrikstrid--add-rust-targets
Add rust targets
- Loading branch information
Showing
8 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import("./app/pkg/app.js").then((app) => app.main()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
cargo --version | ||
rustc --version | ||
|
||
if [[ "$(uname)" == "Darwin" ]]; then | ||
echo "$RUSTFLAGS" | grep -- "-L framework=$DEVENV_PROFILE/Library/Frameworks" | ||
echo "$RUSTDOCFLAGS" | grep -- "-L framework=$DEVENV_PROFILE/Library/Frameworks" | ||
echo "$CFLAGS" | grep -- "-iframework $DEVENV_PROFILE/Library/Frameworks" | ||
fi | ||
|
||
[[ "$CARGO_INSTALL_ROOT" == "$DEVENV_STATE/cargo-install" ]] | ||
echo "$PATH" | grep -- "$CARGO_INSTALL_ROOT/bin" | ||
|
||
wasm-pack build ./app --target nodejs | ||
|
||
node .test.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[package] | ||
name = "app" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2.84" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" | ||
|
||
[workspace] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
// First up let's take a look of binding `console.log` manually, without the | ||
// help of `web_sys`. Here we're writing the `#[wasm_bindgen]` annotations | ||
// manually ourselves, and the correctness of our program relies on the | ||
// correctness of these annotations! | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
// 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_rules! console_log { | ||
// Note that this is using the `log` function imported above during | ||
// `bare_bones` | ||
($($t:tt)*) => (log(&format_args!($($t)*).to_string())) | ||
} | ||
|
||
// Called by our JS entry point to run the example. | ||
#[wasm_bindgen] | ||
pub fn main() { | ||
console_log!("Hello, from devenv!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ pkgs, lib, ... }: | ||
|
||
{ | ||
languages.rust = { | ||
enable = true; | ||
# https://devenv.sh/reference/options/#languagesrustchannel | ||
channel = "nightly"; | ||
|
||
targets = [ "wasm32-unknown-unknown" ]; | ||
|
||
components = [ "rustc" "cargo" "clippy" "rustfmt" "rust-analyzer" "rust-std" ]; | ||
}; | ||
|
||
# These break us | ||
# pre-commit.hooks = { | ||
# rustfmt.enable = true; | ||
# clippy.enable = true; | ||
# }; | ||
|
||
packages = [ | ||
pkgs.wasm-pack | ||
pkgs.nodejs | ||
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk; [ | ||
frameworks.Security | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
inputs: | ||
fenix: | ||
url: github:nix-community/fenix | ||
inputs: | ||
nixpkgs: | ||
follows: nixpkgs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters