-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle projects which have both a bin and lib (cdylib) target
In a previous change `cdylib` targets have been added to the list of allowed artifacts. However, projects which are both a binary as well as a library, the compilation failed now, since both target artifacts (bin and lib) got added to the target output. It was not possible to select by name. This change adds the `data-target-name` attribute to specifically select a target "by name", without having to use the `--bin` argument in cargo. Closes: #630
- Loading branch information
Showing
11 changed files
with
304 additions
and
21 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
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,14 @@ | ||
[package] | ||
name = "cdylib-example" | ||
version = "0.1.0" | ||
authors = ["Jens Reimann <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
console_error_panic_hook = "0.1" | ||
wasm-bindgen = "0.2" | ||
wasm-bindgen-futures = "0.4" | ||
web-sys = { version = "0.3", features = ["Window", "Document", "HtmlElement", "Node", "Text"] } |
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,8 @@ | ||
Trunk | cdylib | web-sys | ||
========================= | ||
An example application demonstrating building a vanilla Rust (no frameworks) WASM web application using web-sys as a | ||
library. | ||
|
||
Once you've installed Trunk, simply execute `trunk serve --open` from this example's directory, and you should see the web application rendered in your browser. | ||
|
||
![Rendered cdylib example](example-vanilla.png) |
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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<title>Trunk | cdylib | web-sys</title> | ||
|
||
<link data-trunk rel="scss" href="src/index.scss"/> | ||
<link data-trunk rel="css" href="src/app.css"/> | ||
<base data-trunk-public-url/> | ||
</head> | ||
<body> | ||
<link data-trunk rel="rust" href="Cargo.toml" /> | ||
<script data-trunk src="src/script.js"></script> | ||
</body> | ||
<script>testFromJavaScript();</script> | ||
</html> |
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 @@ | ||
body {} |
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,9 @@ | ||
@charset "utf-8"; | ||
|
||
html { | ||
body { | ||
font-size: 20pt; | ||
color: #111; | ||
font-family: sans-serif; | ||
} | ||
} |
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,27 @@ | ||
#![recursion_limit = "1024"] | ||
|
||
use console_error_panic_hook::set_once as set_panic_hook; | ||
use wasm_bindgen::prelude::*; | ||
use web_sys::window; | ||
|
||
fn start_app() { | ||
let document = window() | ||
.and_then(|win| win.document()) | ||
.expect("Could not access document"); | ||
let body = document.body().expect("Could not access document.body"); | ||
let text_node = document.create_text_node("Hello, world from cdylib Rust!"); | ||
body.append_child(text_node.as_ref()) | ||
.expect("Failed to append text"); | ||
} | ||
|
||
#[wasm_bindgen(inline_js = "export function snippetTest() { console.log('Hello from JS FFI!'); }")] | ||
extern "C" { | ||
fn snippetTest(); | ||
} | ||
|
||
#[wasm_bindgen(start)] | ||
pub async fn run() { | ||
set_panic_hook(); | ||
snippetTest(); | ||
start_app(); | ||
} |
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,3 @@ | ||
function testFromJavaScript() { | ||
console.log("Hello from JavaScript"); | ||
} |
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
Oops, something went wrong.