Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(wasm): modify turborepo config #780

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/turbo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ jobs:
with:
targets: wasm32-unknown-unknown
- run: pnpm turbo download-keys --cache-dir=.turbo
- run: pnpm run compile --cache-dir=.turbo
- run: pnpm turbo format-check:rust --cache-dir=.turbo
- run: pnpm turbo lint:rust --cache-dir=.turbo

Expand Down Expand Up @@ -143,4 +144,5 @@ jobs:
version: 'latest'
- uses: browser-actions/setup-firefox@v1
- run: pnpm turbo download-keys --cache-dir=.turbo
- run: pnpm run compile --cache-dir=.turbo
- run: pnpm turbo test:rust --cache-dir=.turbo
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
pnpm-lock.yaml
packages/wasm/crate
packages/wasm/wasm
apps/extension/bin
packages/wasm/bin/
1 change: 0 additions & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"description": "chrome-extension",
"type": "module",
"scripts": {
"download-keys": "tsx src/utils/download-proving-keys.ts",
"dev": "webpack --watch --mode=development -d inline-source-map",
"clean": "rm -rfv dist bin",
"build": "webpack",
Expand Down
10 changes: 10 additions & 0 deletions apps/extension/src/utils/download-proving-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ const main = () => {

console.log('Downloading keys', VERSION_TAG, Object.values(provingKeys).join(', '));

// Check if the --force flag is provided in the command-line arguments
const forceDownload = process.argv.includes('--force');

fs.mkdirSync(binDir, { recursive: true });
const downloads = Object.values(provingKeys).map(async name => {
const file = `${name}_pk.bin`;
const outputPath = path.join(binDir, file);

// Check if the file already exists
if (!forceDownload && fs.existsSync(outputPath)) {
console.log(`${file} already downloaded.`);
return;
}

const downloadPath = new URL(`${githubSourceDir}${file}`);

const response = await fetch(downloadPath);
Expand Down
10 changes: 9 additions & 1 deletion apps/extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ export default (env, argv) => {
}),
new webpack.DefinePlugin(definitions),
new CopyPlugin({
patterns: ['public', { from: 'bin', to: 'bin' }],
patterns: [
{ from: 'public', to: '.' },
{
from: 'bin',
to: 'bin',
context: path.resolve(__dirname, '../../packages/wasm'),
noErrorOnMissing: true,
},
],
Comment on lines +115 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there is a more 'conventional' way to bundle assets from a dependency in webpack. i don't have an example on hand but i will see what i can find later

}),
// html entry points
new HtmlWebpackPlugin({
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"build": "turbo run build",
"compile": "turbo run compile",
"dev": "turbo run dev --concurrency 20",
"download-keys": "turbo run download-keys",
"lint": "turbo run lint -- --max-warnings=0",
"lint:rust": "turbo run lint:rust",
"lint:fix": "turbo run lint -- --fix",
Expand All @@ -19,7 +18,8 @@
"playwright-install": "playwright install",
"changeset": "changeset",
"changeset:publish": "changeset publish",
"all-check": "pnpm install && pnpm compile && pnpm format-check && pnpm lint && pnpm test && pnpm download-keys && pnpm build && pnpm format-check:rust && pnpm lint:rust && pnpm test:rust"
"download-keys": "turbo run download-keys",
"all-check": "pnpm install && pnpm compile && pnpm format-check && pnpm lint && pnpm test && pnpm build && pnpm format-check:rust && pnpm lint:rust && pnpm test:rust"
},
"dependencies": {
"@buf/cosmos_ibc.bufbuild_es": "1.7.2-20240215124455-b32ecf3ebbcb.1",
Expand Down
1 change: 1 addition & 0 deletions packages/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
crate/target
crate/**/*.rs.bk
crate/wasm-pack.log
bin/
14 changes: 6 additions & 8 deletions packages/wasm/crate/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ mod tests {
// that are based on constructing objects according to protobuf definitions.

// Load the proving key parameters as byte arrays.
let spend_key: &[u8] = include_bytes!("../../../../apps/extension/bin/spend_pk.bin");
let output_key: &[u8] = include_bytes!("../../../../apps/extension/bin/output_pk.bin");
let delegator_vote_key: &[u8] =
include_bytes!("../../../../apps/extension/bin/delegator_vote_pk.bin");
let swap_key: &[u8] = include_bytes!("../../../../apps/extension/bin/swap_pk.bin");
let swapclaim_key: &[u8] =
include_bytes!("../../../../apps/extension/bin/swapclaim_pk.bin");
let convert_key: &[u8] = include_bytes!("../../../../apps/extension/bin/convert_pk.bin");
let spend_key: &[u8] = include_bytes!("../../bin/spend_pk.bin");
let output_key: &[u8] = include_bytes!("../../bin/output_pk.bin");
let delegator_vote_key: &[u8] = include_bytes!("../../bin/delegator_vote_pk.bin");
let swap_key: &[u8] = include_bytes!("../../bin/swap_pk.bin");
let swapclaim_key: &[u8] = include_bytes!("../../bin/swapclaim_pk.bin");
let convert_key: &[u8] = include_bytes!("../../bin/convert_pk.bin");

// Serialize &[u8] to JsValue.
let spend_key_js: JsValue = serde_wasm_bindgen::to_value(&spend_key).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"license": "MIT",
"type": "module",
"scripts": {
"download-keys": "tsx ../../apps/extension/src/utils/download-proving-keys.ts",
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
"precompile": "npm run download-keys",
"clean": "rm -rfv dist wasm ; cargo clean --manifest-path ./crate/Cargo.toml",
"dev": "cargo watch -C ./crate --postpone -- pnpm turbo run compile",
"compile": "cd crate ; wasm-pack build --no-pack --target bundler --out-name index --out-dir ../wasm",
Expand Down
12 changes: 6 additions & 6 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"build": {
"dotEnv": [".env"],
"env": ["PRAX", "IDB_VERSION", "USDC_ASSET_ID", "MINIFRONT_URL", "PENUMBRA_NODE_PD_URL"],
"dependsOn": ["download-keys", "compile", "^build"],
"dependsOn": ["compile", "^build"],
"outputs": ["dist/**"]
},
"download-keys": {
"inputs": ["src/utils/download-proving-keys.ts"],
"inputs": ["../../apps/extension/src/utils/download-proving-keys.ts"],
"outputs": ["bin/**"]
},
"compile": {
Expand All @@ -26,21 +26,21 @@
"dev": {
"dotEnv": [".env"],
"env": ["PRAX", "IDB_VERSION", "USDC_ASSET_ID", "MINIFRONT_URL", "PENUMBRA_NODE_PD_URL"],
"dependsOn": ["download-keys", "^build"],
"dependsOn": ["^build"],
"outputs": ["dist/**"],
"persistent": true,
"cache": false
},
"test": { "dependsOn": ["compile", "//#playwright-install"], "cache": false },
"test:rust": {
"dependsOn": ["download-keys", "compile"],
"dependsOn": ["compile"],
"inputs": ["crate/src/**", "crate/Cargo.toml", "crate/Cargo.lock", "crate/tests/**"]
},
"lint:rust": {
"dependsOn": ["download-keys", "compile"],
"dependsOn": ["compile"],
"inputs": ["crate/src/**", "crate/Cargo.toml", "crate/Cargo.lock", "crate/tests/**"]
},
"format-check:rust": { "dependsOn": ["download-keys", "compile"] },
"format-check:rust": { "dependsOn": ["compile"] },
"//#playwright-install": { "cache": false },
"clean": {
"cache": false
Expand Down
Loading