Commit bbee7335 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/wasm' into 'main'

Fix/wasm

See merge request !133
parents 4f7bdefa 42450866
Pipeline #20694 passed with stages
in 30 minutes and 12 seconds
stages: stages:
- install - install
- check
- lint - lint
- test - test
- wasm - wasm
...@@ -21,6 +22,25 @@ npm_ci: ...@@ -21,6 +22,25 @@ npm_ci:
dependencies: dependencies:
- npm_ci - npm_ci
# ts_check:
# dependencies:
# - npm_ci
# stage: check
# tags:
# - linux
# before_script:
# - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# script:
# - wasm-pack build ./rust-src --target web
# - npx tsc
rs_check:
stage: check
image: rust:latest
tags:
- linux
script: cd rust-src && cargo check
ts_lint: ts_lint:
extends: .build_base extends: .build_base
stage: lint stage: lint
...@@ -47,7 +67,7 @@ wasm_build: ...@@ -47,7 +67,7 @@ wasm_build:
before_script: before_script:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
script: script:
- cd rust-src && wasm-pack build - wasm-pack build ./rust-src --target web
artifacts: artifacts:
paths: paths:
- rust-src/pkg - rust-src/pkg
...@@ -63,9 +83,9 @@ npm_build: ...@@ -63,9 +83,9 @@ npm_build:
script: script:
- mv neos.config.prod.json neos.config.json - mv neos.config.prod.json neos.config.json
- npm run build:prod - npm run build:prod
- npx tsc
artifacts: artifacts:
paths: paths:
- rust-src/pkg
- dist - dist
deploy: deploy:
...@@ -78,5 +98,4 @@ deploy: ...@@ -78,5 +98,4 @@ deploy:
- npm_build - npm_build
script: script:
- mv neos-assets dist/ - mv neos-assets dist/
- mv rust-src dist/
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://mycard/neos - aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://mycard/neos
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
"react-redux": "^8.0.4", "react-redux": "^8.0.4",
"react-router-dom": "^6.4.0", "react-router-dom": "^6.4.0",
"react-scripts": "^2.1.3", "react-scripts": "^2.1.3",
"rust-src": "file:rust-src/pkg",
"socket.io-client": "^4.5.1", "socket.io-client": "^4.5.1",
"sql.js": "^1.8.0", "sql.js": "^1.8.0",
"vite-plugin-svgr": "^2.4.0", "vite-plugin-svgr": "^2.4.0",
...@@ -52,7 +51,7 @@ ...@@ -52,7 +51,7 @@
"sass": "^1.58.0", "sass": "^1.58.0",
"typescript": "^4.8.4", "typescript": "^4.8.4",
"vite": "^3.1.0", "vite": "^3.1.0",
"vite-plugin-wasm": "^3.2.2" "vite-plugin-wasm-pack": "^0.1.12"
} }
}, },
"node_modules/@adobe/css-tools": { "node_modules/@adobe/css-tools": {
...@@ -15209,6 +15208,12 @@ ...@@ -15209,6 +15208,12 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/narrowing": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/narrowing/-/narrowing-1.5.0.tgz",
"integrity": "sha512-DUu4XdKgkfAPTAL28k79pdnshDE2W5T24QAnidSPo2F/W1TX6CjNzmEeXQfE5O1lxQvC0GYI6ZRDsLcyzugEYA==",
"dev": true
},
"node_modules/natural-compare": { "node_modules/natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
...@@ -22771,10 +22776,6 @@ ...@@ -22771,10 +22776,6 @@
"aproba": "^1.1.1" "aproba": "^1.1.1"
} }
}, },
"node_modules/rust-src": {
"resolved": "rust-src/pkg",
"link": true
},
"node_modules/rxjs": { "node_modules/rxjs": {
"version": "6.6.7", "version": "6.6.7",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz",
...@@ -25915,13 +25916,50 @@ ...@@ -25915,13 +25916,50 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/vite-plugin-wasm": { "node_modules/vite-plugin-wasm-pack": {
"version": "3.2.2", "version": "0.1.12",
"resolved": "https://registry.npmjs.org/vite-plugin-wasm/-/vite-plugin-wasm-3.2.2.tgz", "resolved": "https://registry.npmjs.org/vite-plugin-wasm-pack/-/vite-plugin-wasm-pack-0.1.12.tgz",
"integrity": "sha512-cdbBUNR850AEoMd5nvLmnyeq63CSfoP1ctD/L2vLk/5+wsgAPlAVAzUK5nGKWO/jtehNlrSSHLteN+gFQw7VOA==", "integrity": "sha512-WliYvQp9HXluir4OKGbngkcKxtYtifU11cqLurRRJGsl770Sjr1iIkp5RuvU3IC1poT4A57Z2/YgAKI2Skm7ZA==",
"dev": true, "dev": true,
"peerDependencies": { "dependencies": {
"vite": "^2 || ^3 || ^4" "chalk": "^4.1.2",
"fs-extra": "^10.0.0",
"narrowing": "^1.4.0"
}
},
"node_modules/vite-plugin-wasm-pack/node_modules/fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/vite-plugin-wasm-pack/node_modules/jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dev": true,
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/vite-plugin-wasm-pack/node_modules/universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
"dev": true,
"engines": {
"node": ">= 10.0.0"
} }
}, },
"node_modules/vm-browserify": { "node_modules/vm-browserify": {
...@@ -27140,7 +27178,9 @@ ...@@ -27140,7 +27178,9 @@
} }
}, },
"rust-src/pkg": { "rust-src/pkg": {
"version": "0.1.0" "name": "rust-src",
"version": "0.1.0",
"extraneous": true
} }
}, },
"dependencies": { "dependencies": {
...@@ -38776,6 +38816,12 @@ ...@@ -38776,6 +38816,12 @@
} }
} }
}, },
"narrowing": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/narrowing/-/narrowing-1.5.0.tgz",
"integrity": "sha512-DUu4XdKgkfAPTAL28k79pdnshDE2W5T24QAnidSPo2F/W1TX6CjNzmEeXQfE5O1lxQvC0GYI6ZRDsLcyzugEYA==",
"dev": true
},
"natural-compare": { "natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
...@@ -44519,9 +44565,6 @@ ...@@ -44519,9 +44565,6 @@
"aproba": "^1.1.1" "aproba": "^1.1.1"
} }
}, },
"rust-src": {
"version": "file:rust-src/pkg"
},
"rxjs": { "rxjs": {
"version": "6.6.7", "version": "6.6.7",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz",
...@@ -47004,12 +47047,45 @@ ...@@ -47004,12 +47047,45 @@
} }
} }
}, },
"vite-plugin-wasm": { "vite-plugin-wasm-pack": {
"version": "3.2.2", "version": "0.1.12",
"resolved": "https://registry.npmjs.org/vite-plugin-wasm/-/vite-plugin-wasm-3.2.2.tgz", "resolved": "https://registry.npmjs.org/vite-plugin-wasm-pack/-/vite-plugin-wasm-pack-0.1.12.tgz",
"integrity": "sha512-cdbBUNR850AEoMd5nvLmnyeq63CSfoP1ctD/L2vLk/5+wsgAPlAVAzUK5nGKWO/jtehNlrSSHLteN+gFQw7VOA==", "integrity": "sha512-WliYvQp9HXluir4OKGbngkcKxtYtifU11cqLurRRJGsl770Sjr1iIkp5RuvU3IC1poT4A57Z2/YgAKI2Skm7ZA==",
"dev": true, "dev": true,
"requires": {} "requires": {
"chalk": "^4.1.2",
"fs-extra": "^10.0.0",
"narrowing": "^1.4.0"
},
"dependencies": {
"fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
}
},
"jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
}
},
"universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
"dev": true
}
}
}, },
"vm-browserify": { "vm-browserify": {
"version": "1.1.2", "version": "1.1.2",
...@@ -30,14 +30,13 @@ ...@@ -30,14 +30,13 @@
"sql.js": "^1.8.0", "sql.js": "^1.8.0",
"vite-plugin-svgr": "^2.4.0", "vite-plugin-svgr": "^2.4.0",
"web-vitals": "^2.1.4", "web-vitals": "^2.1.4",
"ygopro-deck-encode": "^1.0.3", "ygopro-deck-encode": "^1.0.3"
"rust-src": "file:rust-src/pkg"
}, },
"scripts": { "scripts": {
"wasm": "cd rust-src && wasm-pack build", "wasm": "wasm-pack build ./rust-src --target web",
"dev": "npm run wasm && vite", "dev": "npm run wasm && vite",
"build": "tsc && vite build && cp -r neos-assets dist/", "build": "vite build && cp -r neos-assets dist/",
"build:prod": "tsc && vite build --base=https://cdn02.moecube.com:444/neos/", "build:prod": "vite build --base=https://cdn02.moecube.com:444/neos/",
"preview": "vite preview", "preview": "vite preview",
"lint": "eslint --ext .ts --ext .tsx src", "lint": "eslint --ext .ts --ext .tsx src",
"fmt": "eslint --ext .ts --ext .tsx src --fix && cd rust-src && cargo fmt", "fmt": "eslint --ext .ts --ext .tsx src --fix && cd rust-src && cargo fmt",
...@@ -76,6 +75,6 @@ ...@@ -76,6 +75,6 @@
"sass": "^1.58.0", "sass": "^1.58.0",
"typescript": "^4.8.4", "typescript": "^4.8.4",
"vite": "^3.1.0", "vite": "^3.1.0",
"vite-plugin-wasm": "^3.2.2" "vite-plugin-wasm-pack": "^0.1.12"
} }
} }
import { ygopro } from "../../../idl/ocgcore"; import { ygopro } from "../../../idl/ocgcore";
import { ocgDamageAdapter } from "rust-src"; import init, { ocgDamageAdapter } from "rust-src";
/* /*
* Msg Damage * Msg Damage
...@@ -7,8 +7,8 @@ import { ocgDamageAdapter } from "rust-src"; ...@@ -7,8 +7,8 @@ import { ocgDamageAdapter } from "rust-src";
* @param player - 玩家编号 * @param player - 玩家编号
* @param value - 减少的Hp数值 * @param value - 减少的Hp数值
* */ * */
export default (data: Uint8Array) => { export default async (data: Uint8Array) => {
const damage = ocgDamageAdapter(data); const damage = await init().then(() => ocgDamageAdapter(data));
return new ygopro.StocGameMessage.MsgUpdateHp(damage); return new ygopro.StocGameMessage.MsgUpdateHp(damage);
}; };
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import svgr from 'vite-plugin-svgr' import svgr from 'vite-plugin-svgr'
import wasm from "vite-plugin-wasm"; import wasmPack from 'vite-plugin-wasm-pack';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react(), svgr(), wasm()] plugins: [react(), svgr(), wasmPack('./rust-src')]
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment