-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets. Adds `craneLib.buildTrunkPackage`, a function that builds a Trunk project returning a directory with the resulting dist files for that project
- Loading branch information
lelgenio
committed
Apr 27, 2023
1 parent
54b63c8
commit cc2f119
Showing
32 changed files
with
3,175 additions
and
0 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
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
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
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,46 @@ | ||
{ pkgs | ||
, myLib | ||
, runCommand | ||
}: | ||
|
||
let | ||
wasmToolchain = pkgs.rust-bin.stable.latest.default.override { | ||
targets = [ "wasm32-unknown-unknown" ]; | ||
}; | ||
|
||
myLibWasm = myLib.overrideToolchain wasmToolchain; | ||
|
||
defaultArgs = { | ||
src = ./trunk; | ||
doCheck = false; | ||
}; | ||
|
||
# default build | ||
cargoArtifacts = myLibWasm.buildDepsOnly (defaultArgs // { | ||
cargoExtraArgs = "--target=wasm32-unknown-unknown"; | ||
}); | ||
trunkSimple = myLibWasm.buildTrunkPackage (defaultArgs // { | ||
inherit cargoArtifacts; | ||
pname = "trunk-simple"; | ||
}); | ||
|
||
# Trying to build when cargoArtifacts does not contain | ||
# the wasm32-unknown-unknown target should throw an exception | ||
cargoArtifactsIncorrectArgs = myLibWasm.buildDepsOnly defaultArgs; | ||
trunkSimpleIncorrectArgs = myLibWasm.buildTrunkPackage (defaultArgs // { | ||
cargoArtifacts = cargoArtifactsIncorrectArgs; | ||
pname = "trunk-simple-incorrect-args"; | ||
}); | ||
|
||
trunkSimpleNoArtifacts = myLibWasm.buildTrunkPackage (defaultArgs // { | ||
pname = "trunk-simple-no-artifacts"; | ||
}); | ||
in | ||
|
||
assert (builtins.tryEval trunkSimpleIncorrectArgs).success == false; | ||
|
||
runCommand "trunkTests" { } '' | ||
test -f ${trunkSimple}/*.wasm | ||
test -f ${trunkSimpleNoArtifacts}/*.wasm | ||
mkdir -p $out | ||
'' |
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,8 @@ | ||
[package] | ||
name = "trunk" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
console_log = "1.0.0" | ||
log = "0.4.17" |
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,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Trunk App</title> | ||
</head> | ||
</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,4 @@ | ||
fn main() { | ||
console_log::init().unwrap(); | ||
log::debug!("Hi, this can run on the browser"); | ||
} |
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
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
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,20 @@ | ||
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets. | ||
It can be used in conjunction with any of Rust's web frameworks for the development of full stack web applications. | ||
|
||
In this example we have a workspace with three members: | ||
|
||
* client: a Yew application compiled using Trunk | ||
* server: a Axum server built using Cargo | ||
* shared: a library that contains types to be imported in both the client and server | ||
|
||
Quick-start a Trunk+Server project with | ||
|
||
```sh | ||
nix flake init -t github:ipetkov/crane#trunk-workspace | ||
``` | ||
|
||
Alternatively, copy and paste the following `flake.nix` and modify it to build your workspace's packages: | ||
|
||
```nix | ||
{{#include ../../examples/trunk-workspace/flake.nix}} | ||
``` |
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,19 @@ | ||
[Trunk](https://trunkrs.dev) is a tool that allow you to build web apps using Rust and webassembly, including compiling scss, and distributing other assets. | ||
|
||
Being a more specialized tool, it comes with some constraints that must be noted when using it in combination with crane: | ||
|
||
* Your Toolchain must have the `wasm32-unknown-unknown` target installed (See: [Custom toolchain](../custom-toolchain.md)) | ||
* For `craneLib.buildDepsOnly` to work you will need to set the build target (See: [API Reference](../API.md#libbuilddepsonly)) | ||
* `craneLib.filterCargoSources` will remove html, css, your assets folder, so you need to modify the source filtering function (See: [Source filtering](../source-filtering.md)) | ||
|
||
Quick-start a Trunk project with | ||
|
||
```sh | ||
nix flake init -t github:ipetkov/crane#trunk | ||
``` | ||
|
||
Alternatively, copy and paste the following `flake.nix`: | ||
|
||
```nix | ||
{{#include ../../examples/trunk/flake.nix}} | ||
``` |
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
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 @@ | ||
client/dist |
Oops, something went wrong.