diff --git a/README.md b/README.md index 958fdf7c5f..bb789df951 100644 --- a/README.md +++ b/README.md @@ -48,14 +48,38 @@ We recommend downloading the latest application binary from [our Releases page]( ## Running a development build -First, [install Rust via `rustup`](https://www.rust-lang.org/tools/install). This project uses a lot of Rust compiled to [WASM](https://webassembly.org/) within it. We always use the latest stable version of Rust, so you may need to run `rustup update stable`. Then, run: +Install a node version manager such as [fnm](https://github.com/Schniz/fnm). +``` +# macOS/Linux +curl -fsSL https://fnm.vercel.app/install | bash + +# Windows +winget install Schniz.fnm +``` + +Then in the repo +``` +fnm install --corepack-enabled +``` + +Install the NPM dependencies with: ``` yarn install ``` -followed by: +This project uses a lot of Rust compiled to [WASM](https://webassembly.org/) within it. We always use the latest stable version of Rust, so you may need to run `rustup update stable`. We have package scripts to run rustup, see `package.json` for reference: +``` +# macOS/Linux +yarn install:rust +yarn install:wasm-pack + +# Windows +yarn install:rust:windows +yarn install:wasm-pack:windows +``` +Then to build the WASM layer, run: ``` yarn build:wasm ``` @@ -74,7 +98,7 @@ Finally, to run the web app only, run: yarn start ``` -If you're not an KittyCAD employee you won't be able to access the dev environment, you should copy everything from `.env.production` to `.env.development` to make it point to production instead, then when you navigate to `localhost:3000` the easiest way to sign in is to paste `localStorage.setItem('TOKEN_PERSIST_KEY', "your-token-from-https://zoo.dev/account/api-tokens")` replacing the with a real token from https://zoo.dev/account/api-tokens of course, then navigate to localhost:3000 again. Note that navigating to `localhost:3000/signin` removes your token so you will need to set the token again. +If you're not a Zoo employee you won't be able to access the dev environment, you should copy everything from `.env.production` to `.env.development` to make it point to production instead, then when you navigate to `localhost:3000` the easiest way to sign in is to paste `localStorage.setItem('TOKEN_PERSIST_KEY', "your-token-from-https://zoo.dev/account/api-tokens")` replacing the with a real token from https://zoo.dev/account/api-tokens of course, then navigate to localhost:3000 again. Note that navigating to `localhost:3000/signin` removes your token so you will need to set the token again. ### Development environment variables diff --git a/package.json b/package.json index 8610744d7b..6aaa4a137f 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "start": "vite --port=3000 --host=0.0.0.0", "start:prod": "vite preview --port=3000", "serve": "vite serve --port=3000", - "build": "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source \"$HOME/.cargo/env\" && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -y && yarn build:wasm && vite build", + "build": "yarn build:wasm && vite build", "build:local": "vite build", "build:both": "vite build", "build:both:local": "yarn build:wasm && vite build", @@ -84,7 +84,13 @@ "simpleserver:stop": "kill-port 3000", "fmt": "prettier --write ./src *.ts *.json *.js ./e2e ./packages", "fmt-check": "prettier --check ./src *.ts *.json *.js ./e2e ./packages", - "fetch:wasm": "./get-latest-wasm-bundle.sh", + "install:rust": "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source \"$HOME/.cargo/env\"", + "install:rust:windows": "winget install Microsoft.VisualStudio.2022.Community --silent --override \"--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended\" && winget install Rustlang.Rustup", + "install:wasm-pack": "curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -y", + "install:wasm-pack:windows": "cargo install wasm-pack", + "install:tools:windows": "winget install jqlang.jq MikeFarah.yq", + "fetch:wasm": "./scripts/get-latest-wasm-bundle.sh", + "fetch:wasm:windows": "./scripts/get-latest-wasm-bundle.ps1", "fetch:samples": "echo \"Fetching latest KCL samples...\" && curl -o public/kcl-samples-manifest-fallback.json https://raw.githubusercontent.com/KittyCAD/kcl-samples/achalmers/kw-pattern-transform2/manifest.json", "isomorphic-copy-wasm": "(copy src/wasm-lib/pkg/wasm_lib_bg.wasm public || cp src/wasm-lib/pkg/wasm_lib_bg.wasm public)", "build:wasm-dev": "yarn wasm-prep && (cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg && cargo test -p kcl-lib export_bindings) && yarn isomorphic-copy-wasm && yarn fmt", @@ -96,6 +102,7 @@ "files:set-version": "echo \"$(jq --arg v \"$VERSION\" '.version=$v' package.json --indent 2)\" > package.json", "files:set-notes": "./scripts/set-files-notes.sh", "files:flip-to-nightly": "./scripts/flip-files-to-nightly.sh", + "files:flip-to-nightly:windows": "./scripts/flip-files-to-nightly.ps1", "files:invalidate-bucket": "./scripts/invalidate-files-bucket.sh", "files:invalidate-bucket:nightly": "./scripts/invalidate-files-bucket.sh --nightly", "postinstall": "yarn fetch:samples && yarn xstate:typegen && ./node_modules/.bin/electron-rebuild", @@ -207,7 +214,6 @@ "vite-tsconfig-paths": "^4.3.2", "vitest": "^1.6.1", "vitest-webgl-canvas-mock": "^1.1.0", - "wasm-pack": "^0.13.1", "ws": "^8.17.0", "yarn": "^1.22.22" }, diff --git a/scripts/flip-files-to-nightly.ps1 b/scripts/flip-files-to-nightly.ps1 new file mode 100644 index 0000000000..5c0fac15d5 --- /dev/null +++ b/scripts/flip-files-to-nightly.ps1 @@ -0,0 +1,20 @@ +$env:VERSION=(Get-Date -Format "yy.M.d") +$env:COMMIT=$(git rev-parse --short HEAD) +$env:PRODUCT_NAME="Zoo Modeling App (Nightly)" + +# package.json +yq -i '.version = env(VERSION)' -p=json -o=json package.json +yq -i '.productName = env(PRODUCT_NAME)' -p=json -o=json package.json +yq -i '.name = ""zoo-modeling-app-nightly""' -p=json -o=json package.json + +# electron-builder.yml +yq -i '.publish[0].url = ""https://dl.zoo.dev/releases/modeling-app/nightly""' electron-builder.yml +yq -i '.appId = ""dev.zoo.modeling-app-nightly""' electron-builder.yml +yq -i '.nsis.include = ""./scripts/installer-nightly.nsh""' electron-builder.yml + +# Release notes +echo "Nightly build $VERSION (commit $COMMIT)" > release-notes.md + +# icons +cp assets/icon-nightly.png assets/icon.png +cp assets/icon-nightly.ico assets/icon.ico diff --git a/scripts/get-latest-wasm-bundle.ps1 b/scripts/get-latest-wasm-bundle.ps1 new file mode 100644 index 0000000000..4dd7afb184 --- /dev/null +++ b/scripts/get-latest-wasm-bundle.ps1 @@ -0,0 +1,13 @@ +$REPO_OWNER = "KittyCAD" +$REPO_NAME = "modeling-app" +$WORKFLOW_NAME = "build-and-store-wasm.yml" +$ARTIFACT_NAME = "wasm-bundle" + +# Fetch the latest completed workflow run ID for the specified workflow +$RUN_ID = (gh run list -w $WORKFLOW_NAME --repo $REPO_OWNER/$REPO_NAME --limit 1 --json databaseId -s completed --jq 'first | .databaseId') -join [Environment]::NewLine + +$PKG_PATH="./src/wasm-lib/pkg/" +rm -r $PKG_PATH/* +gh run download $RUN_ID --repo $REPO_OWNER/$REPO_NAME --name $ARTIFACT_NAME --dir $PKG_PATH +cp $PKG_PATH/wasm_lib_bg.wasm public +echo "latest wasm copied to public folder" diff --git a/get-latest-wasm-bundle.sh b/scripts/get-latest-wasm-bundle.sh old mode 100755 new mode 100644 similarity index 100% rename from get-latest-wasm-bundle.sh rename to scripts/get-latest-wasm-bundle.sh diff --git a/src/wasm-lib/Cargo.toml b/src/wasm-lib/Cargo.toml index 1e5b68891d..0d32e08a3f 100644 --- a/src/wasm-lib/Cargo.toml +++ b/src/wasm-lib/Cargo.toml @@ -101,3 +101,6 @@ path = "tests/modify/main.rs" #[patch.crates-io] #kittycad-modeling-cmds = { path = "../../../modeling-api/modeling-cmds" } #kittycad-modeling-session = { path = "../../../modeling-api/modeling-session" } + +[package.metadata.wasm-pack.profile.release] +wasm-opt = false diff --git a/yarn.lock b/yarn.lock index 1ca42043a3..48a13d302d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3170,13 +3170,6 @@ axe-core@^4.10.0: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.10.2.tgz#85228e3e1d8b8532a27659b332e39b7fa0e022df" integrity sha512-RE3mdQ7P3FRSe7eqCWoeQ/Z9QXrtniSjp1wUjt5nRC3WIpz5rSCve6o3fsZ2aCpJtrZjSZgjwXAoTO5k4tEI0w== -axios@^0.26.1: - version "0.26.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" - integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA== - dependencies: - follow-redirects "^1.14.8" - axobject-query@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-4.1.0.tgz#28768c76d0e3cff21bc62a9e2d0b6ac30042a1ee" @@ -3238,15 +3231,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522" integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== -binary-install@^1.0.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/binary-install/-/binary-install-1.1.0.tgz#61195349acabf5a043f3805b03f96e506cc96d6e" - integrity sha512-rkwNGW+3aQVSZoD0/o3mfPN6Yxh3Id0R/xzTVBVVpGNlVz8EGwusksxRlbk/A5iKTZt9zkMn3qIqmAt3vpfbzg== - dependencies: - axios "^0.26.1" - rimraf "^3.0.2" - tar "^6.1.11" - bl@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" @@ -5149,11 +5133,6 @@ follow-redirects@^1.0.0: resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== -follow-redirects@^1.14.8: - version "1.15.9" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" - integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ== - for-each@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e" @@ -9567,13 +9546,6 @@ warning@^4.0.3: dependencies: loose-envify "^1.0.0" -wasm-pack@^0.13.1: - version "0.13.1" - resolved "https://registry.yarnpkg.com/wasm-pack/-/wasm-pack-0.13.1.tgz#345701522420ad74a5b584f1bdaf6db8c264cb54" - integrity sha512-P9exD4YkjpDbw68xUhF3MDm/CC/3eTmmthyG5bHJ56kalxOTewOunxTke4SyF8MTXV6jUtNjXggPgrGmMtczGg== - dependencies: - binary-install "^1.0.1" - wcwidth@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"