Skip to content

Commit b960720

Browse files
committed
Using Large Project Architecture
1 parent a44d627 commit b960720

33 files changed

+840
-42
lines changed

.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[build]
2+
#target = "wasm32-wasip2"

.editorconfig

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
[*]
22
charset = utf-8
3-
tab_width = 4
4-
insert_final_newline = true
5-
trim_trailing_whitespace = true
63

7-
[*.ts]
8-
indent_style = space
9-
indent_size = 4
104

11-
[*.yaml]
5+
[*.pest]
126
indent_style = space
13-
indent_size = 2
7+
indent_size = 4
148

15-
[*.json]
9+
[*.toml]
1610
indent_style = space
17-
indent_size = 4
11+
indent_size = 4

.github/workflows/rust.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ master, dev ]
6+
pull_request:
7+
branches: [ master, dev ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
steps:
16+
- run: git config --global core.autocrlf false
17+
- uses: actions/checkout@v2
18+
- name: Rust Nightly
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
toolchain: nightly
22+
override: true
23+
components: rustfmt, clippy
24+
- name: Build
25+
run: cargo build --release
26+
- name: Tests
27+
run: cargo test --release

.gitignore

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
# IDEs
2-
.vscode
3-
.idea
4-
.vs
1+
# OS
2+
.DS_Store/
3+
thumbs.db
4+
time-travel.*
55

6-
# Node
7-
node_modules/**
8-
yarn.lock
9-
dist/**
6+
# IDE
7+
.vscode/
8+
.vs/
9+
.idea/
10+
*.iml
11+
12+
# Rust
13+
target/
14+
Cargo.lock
1015

11-
# Release
12-
*.vsix
13-
*.tgz
16+
# Node
17+
node_modules/
18+
legion-wasm32-wasi.wasm
19+
package-lock.json

.run/build wasi target.run.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="build wasi target" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="buildProfileId" value="release" />
4+
<option name="command" value="build --target wasm32-wasip2" />
5+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
6+
<envs />
7+
<option name="emulateTerminal" value="true" />
8+
<option name="channel" value="DEFAULT" />
9+
<option name="requiredFeatures" value="true" />
10+
<option name="allFeatures" value="false" />
11+
<option name="withSudo" value="false" />
12+
<option name="buildTarget" value="REMOTE" />
13+
<option name="backtrace" value="SHORT" />
14+
<option name="isRedirectInput" value="false" />
15+
<option name="redirectInputPath" value="" />
16+
<method v="2" />
17+
</configuration>
18+
</component>

.run/build-wasi.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cargo build --release --target wasm32-wasip2
2+
cp target/wasm32-wasip2/release/legion.wasm projects/legion-wasm32-wasi/legion-wasm32-wasi.wasm
3+
jco transpile projects/legion-wasm32-wasi/legion-wasm32-wasi.wasm -o projects/legion-wasm32-wasi/src --name index --no-namespaced-exports --multi-memory --valid-lifting-optimization --optimize
4+
5+
cp target/wasm32-wasip2/release/v.wasm projects/v-wasm32-wasi/v-wasm32-wasi.wasm
6+
jco transpile projects/v-wasm32-wasi/v-wasm32-wasi.wasm -o projects/v-wasm32-wasi/src --name index --no-namespaced-exports --multi-memory --valid-lifting-optimization --optimize

.run/copy to npm.run.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="copy to npm" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="buildProfileId" value="test" />
4+
<option name="command" value="test --package legion --lib cli_cmds::cmd_decode::tests::decode2 -- --exact" />
5+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
6+
<envs />
7+
<option name="emulateTerminal" value="true" />
8+
<option name="channel" value="DEFAULT" />
9+
<option name="requiredFeatures" value="true" />
10+
<option name="allFeatures" value="false" />
11+
<option name="withSudo" value="false" />
12+
<option name="buildTarget" value="REMOTE" />
13+
<option name="backtrace" value="SHORT" />
14+
<option name="isRedirectInput" value="false" />
15+
<option name="redirectInputPath" value="" />
16+
<method v="2" />
17+
</configuration>
18+
</component>

Cargo.toml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["projects/*"]
4+
default-members = [
5+
# "projects/v-cli",
6+
"projects/publish-rs",
7+
]
8+
exclude = [
9+
"projects/.DS_Store",
10+
"projects/publish-wasm32-wasi",
11+
]
12+
13+
[profile.release]
14+
lto = true
15+
panic = "abort"
16+
17+
[workspace.dependencies.tokio]
18+
version = "1.43.0"
19+
default-features = true
20+
features = ["macros", "rt"]
21+
22+
[workspace.dependencies.reqwest]
23+
version = "0.12.12"
24+
default-features = false
25+
features = ["rustls-tls", "json", "socks"]
26+
27+
#[workspace.dependencies.wasmtime]
28+
#version = "28.0.0"
29+
#default-features = false
30+
#features = [
31+
# "cranelift",
32+
# "gc-drc",
33+
# "component-model",
34+
#]
35+
#[workspace.dependencies.wasmtime-wasi]
36+
#version = "28.0.0"
37+
#default-features = false

action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ branding:
1010
inputs:
1111
wasm:
1212
description: 'Optional version of wasm-pack to install (eg. "v0.9.1", "latest")'
13+
required: false
1314
default: 'latest'
1415
trunk:
1516
description: 'Optional version of trunk to install (eg. "v0.6.0", "latest")'
17+
required: false
1618
default: 'latest'
1719
outputs:
1820
DEPLOYMENT_STATUS:

package.json

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
{
2-
"name": "github-pages-with-rust",
3-
"description": "GitHub action for building a project and deploying it to GitHub pages.",
4-
"author": "Aster <[email protected]>",
5-
"version": "0.1.0",
62
"private": true,
7-
"license": "MLP 2.0",
8-
"main": "dist/index.js",
9-
"types": "dist/index.d.ts",
3+
"workspaces": [
4+
"projects/*"
5+
],
106
"scripts": {
11-
"build": "wee lint && tsc -b",
12-
"lint": "tslint **/*.ts --fix",
13-
"reset": "git reset Head~ --soft"
14-
},
15-
"dependencies": {
16-
"@actions/core": "1.2.6",
17-
"@actions/exec": "1.0.4",
18-
"@actions/github": "4.0.0",
19-
"@actions/io": "1.0.2",
20-
"@actions/tool-cache": "^1.6.0",
21-
"typed-rest-client": "^1.7.3"
7+
"build": "cargo build --release",
8+
"test": "cargo test --release",
9+
"fmt": "cargo fmt --all",
10+
"p": "git push && git push --tags --prune",
11+
"reset": "git reset Head~ --soft",
12+
"u": "cargo upgrade --incompatible"
2213
},
2314
"devDependencies": {
24-
"@types/jest": "26.0.14",
25-
"@types/node": "14.11.2",
26-
"typescript": "3.9.7"
15+
"@bytecodealliance/jco": "^1.8.1",
16+
"@types/node": "^22",
17+
"typescript": "^5.7.2"
2718
}
2819
}

projects/publish-rs/Cargo.toml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "legion"
3+
version = "0.1.0"
4+
authors = ["Aster <[email protected]>"]
5+
description = "Valkyrie workspace manager"
6+
repository = "https://github.com/nyar-vm/valkyrie-valor"
7+
documentation = "https://docs.rs/valor-config"
8+
readme = "readme.md"
9+
license = "MPL-2.0"
10+
edition = "2021"
11+
12+
[dependencies]
13+
anyhow = "1.0.95"
14+
clap = { version = "4.5.27", features = ["derive"] }
15+
#url = "2.5.4"
16+
wat = { version = "1.224.0", features = ["component-model", "dwarf"] }
17+
wasmprinter = { version = "0.224.0", features = ["component-model"] }
18+
js-component-bindgen = "1.9.1"
19+
reqwest = { version = "0.12.12", features = ["socks"] }
20+
#inquire = "0.7.5"
21+
dialoguer = "0.11.0"
22+
tokio = { version = "1.43.0", features = ["rt", "macros"] }
23+
tempfile = { version = "3.16.0", features = ["nightly"] }
24+
25+
[dev-dependencies]
26+
27+
[features]
28+
default = []
29+
30+
[package.metadata.component]
31+
package = "legion:tools"

projects/publish-rs/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"b": "cargo component build",
5+
"p": "cargo publish --allow-dirty"
6+
}
7+
}

projects/publish-rs/readme.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
### Configuration file query order
4+
5+
```sh
6+
legion.toml
7+
legion.json5
8+
legion.yaml
9+
legion.yml
10+
legion.json
11+
.config/*
12+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
use crate::{GithubError, commands::LegionArguments};
2+
use clap::Parser;
3+
#[cfg(feature = "wasm-opt")]
4+
use wasm_opt::{OptimizationOptions, OptimizeLevel, ShrinkLevel};
5+
6+
#[derive(Debug, Parser)]
7+
pub struct CommandBuild {
8+
/// Package to build (see `cargo help pkgid`)
9+
#[arg(short, long, visible_alias = "include", value_name = "packages...")]
10+
package: Vec<String>,
11+
/// Exclude packages from the build
12+
#[arg(long, value_name = "packages...")]
13+
exclude: Vec<String>,
14+
/// Build only this package's library
15+
#[arg(short, long, visible_alias = "lib")]
16+
library: bool,
17+
/// Build only the specified binary
18+
#[arg(short, long, visible_alias = "bin", value_name = "binaries...")]
19+
binary: Vec<String>,
20+
#[arg(long = "O0")]
21+
optimize_0: bool,
22+
#[arg(long = "O1")]
23+
optimize_1: bool,
24+
#[arg(long = "O2")]
25+
optimize_2: bool,
26+
#[arg(long = "O3")]
27+
optimize_3: bool,
28+
#[arg(long = "O4")]
29+
optimize_4: bool,
30+
/// Sent to the O5 Council, optimized by the O5 herself.
31+
#[arg(long = "O5")]
32+
optimize_5: bool,
33+
/// Optimize for size
34+
#[arg(long = "Os")]
35+
optimize_s: bool,
36+
/// Optimize for size in aggressively way
37+
#[arg(long = "Oz")]
38+
optimize_z: bool,
39+
}
40+
41+
impl CommandBuild {
42+
#[cfg(feature = "wasm-opt")]
43+
pub async fn run(self, _: &LegionArguments) -> Result<(), GithubError> {
44+
let mut options = OptimizationOptions {
45+
reader: Default::default(),
46+
writer: Default::default(),
47+
inlining: Default::default(),
48+
passopts: Default::default(),
49+
passes: Default::default(),
50+
features: Default::default(),
51+
converge: false,
52+
};
53+
self.optimize_level(&mut options)?;
54+
println!("{:#?}", options);
55+
Ok(())
56+
}
57+
#[cfg(not(feature = "wasm-opt"))]
58+
pub async fn run(self, _: &LegionArguments) -> Result<(), GithubError> {
59+
println!("Unable to build because: https://github.com/dtolnay/cxx/issues/1429");
60+
Ok(())
61+
}
62+
#[cfg(feature = "wasm-opt")]
63+
pub fn optimize_level(&self, options: &mut OptimizationOptions) -> Result<(), GithubError> {
64+
if self.optimize_5 {
65+
panic!("The O5 Council does not exist!");
66+
}
67+
else if self.optimize_z {
68+
options.passopts.optimize_level = OptimizeLevel::Level2;
69+
options.passopts.shrink_level = ShrinkLevel::Level2;
70+
options.passes.add_default_passes = true;
71+
}
72+
else if self.optimize_s {
73+
options.passopts.optimize_level = OptimizeLevel::Level2;
74+
options.passopts.shrink_level = ShrinkLevel::Level2;
75+
options.passes.add_default_passes = true;
76+
}
77+
else if self.optimize_4 {
78+
options.passopts.optimize_level = OptimizeLevel::Level2;
79+
options.passopts.shrink_level = ShrinkLevel::Level2;
80+
options.passes.add_default_passes = true;
81+
}
82+
else if self.optimize_3 {
83+
options.passopts.optimize_level = OptimizeLevel::Level2;
84+
options.passopts.shrink_level = ShrinkLevel::Level2;
85+
options.passes.add_default_passes = true;
86+
}
87+
else if self.optimize_2 {
88+
options.passopts.optimize_level = OptimizeLevel::Level2;
89+
options.passopts.shrink_level = ShrinkLevel::Level2;
90+
options.passes.add_default_passes = true;
91+
}
92+
else if self.optimize_1 {
93+
options.passopts.optimize_level = OptimizeLevel::Level2;
94+
options.passopts.shrink_level = ShrinkLevel::Level2;
95+
options.passes.add_default_passes = true;
96+
}
97+
else if self.optimize_0 {
98+
options.passopts.optimize_level = OptimizeLevel::Level2;
99+
options.passopts.shrink_level = ShrinkLevel::Level2;
100+
options.passes.add_default_passes = true;
101+
}
102+
Ok(())
103+
}
104+
}

0 commit comments

Comments
 (0)