Skip to content

Commit

Permalink
なんかWASMがビルドできなくなってた
Browse files Browse the repository at this point in the history
  • Loading branch information
kurehajime committed Jun 22, 2024
1 parent 964b639 commit 240c04b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "./i18n/configs"
import { Util } from './static/Util'
import Colamone from './components/Colamone'
import { RecoilRoot } from 'recoil'
import init from '../wasm/pkg'
import __wbg_init from '../wasm/pkg/colamone'
// wasm初期化
try {
init()
__wbg_init()
} catch (error) {
console.log(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Aijs } from "../static/game/Ai"
import Cookie from "../static/Cookie"
import { Hand, MapArray, Rule } from "../static/game/Rule"
import { Util } from "../static/Util"
import { think_ai } from '../../wasm/pkg'
import { think_ai } from '../../wasm/pkg/colamone'

export default class GameState {
public turnPlayer = 0
Expand Down
5 changes: 3 additions & 2 deletions wasm/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
version: '3'
services:
rust:
image: rust
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/usr/src/myapp
build: ./
command: bash -c "wasm-pack build --target web && rm ./pkg/.gitignore"
4 changes: 2 additions & 2 deletions wasm/pkg/colamone.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface InitOutput {
readonly __wbg_get_result_to: (a: number) => number;
readonly __wbg_set_result_to: (a: number, b: number) => void;
readonly think_ai: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_malloc: (a: number, b: number) => number;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
Expand All @@ -51,4 +51,4 @@ export function initSync(module: SyncInitInput): InitOutput;
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
68 changes: 38 additions & 30 deletions wasm/pkg/colamone.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@

let wasm;

const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );

cachedTextDecoder.decode();
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };

let cachedUint8Memory0 = new Uint8Array();
let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0.byteLength === 0) {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

let WASM_VECTOR_LEN = 0;

function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
const ptr = malloc(arg.length * 1, 1) >>> 0;
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
Expand All @@ -39,21 +39,25 @@ export function think_ai(map, turn_player, depth) {
return Result.__wrap(ret);
}

const ResultFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_result_free(ptr >>> 0));
/**
*/
export class Result {

static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(Result.prototype);
obj.ptr = ptr;

obj.__wbg_ptr = ptr;
ResultFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}

__destroy_into_raw() {
const ptr = this.ptr;
this.ptr = 0;

const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ResultFinalization.unregister(this);
return ptr;
}

Expand All @@ -65,31 +69,31 @@ export class Result {
* @returns {number}
*/
get from() {
const ret = wasm.__wbg_get_result_from(this.ptr);
const ret = wasm.__wbg_get_result_from(this.__wbg_ptr);
return ret >>> 0;
}
/**
* @param {number} arg0
*/
set from(arg0) {
wasm.__wbg_set_result_from(this.ptr, arg0);
wasm.__wbg_set_result_from(this.__wbg_ptr, arg0);
}
/**
* @returns {number}
*/
get to() {
const ret = wasm.__wbg_get_result_to(this.ptr);
const ret = wasm.__wbg_get_result_to(this.__wbg_ptr);
return ret >>> 0;
}
/**
* @param {number} arg0
*/
set to(arg0) {
wasm.__wbg_set_result_to(this.ptr, arg0);
wasm.__wbg_set_result_to(this.__wbg_ptr, arg0);
}
}

async function load(module, imports) {
async function __wbg_load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
Expand Down Expand Up @@ -120,7 +124,7 @@ async function load(module, imports) {
}
}

function getImports() {
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
Expand All @@ -130,49 +134,53 @@ function getImports() {
return imports;
}

function initMemory(imports, maybe_memory) {
function __wbg_init_memory(imports, maybe_memory) {

}

function finalizeInit(instance, module) {
function __wbg_finalize_init(instance, module) {
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
cachedUint8Memory0 = new Uint8Array();
__wbg_init.__wbindgen_wasm_module = module;
cachedUint8Memory0 = null;


return wasm;
}

function initSync(module) {
const imports = getImports();
if (wasm !== undefined) return wasm;

initMemory(imports);
const imports = __wbg_get_imports();

__wbg_init_memory(imports);

if (!(module instanceof WebAssembly.Module)) {
module = new WebAssembly.Module(module);
}

const instance = new WebAssembly.Instance(module, imports);

return finalizeInit(instance, module);
return __wbg_finalize_init(instance, module);
}

async function init(input) {
async function __wbg_init(input) {
if (wasm !== undefined) return wasm;

if (typeof input === 'undefined') {
input = new URL('colamone_bg.wasm', import.meta.url);
}
const imports = getImports();
const imports = __wbg_get_imports();

if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
input = fetch(input);
}

initMemory(imports);
__wbg_init_memory(imports);

const { instance, module } = await load(await input, imports);
const { instance, module } = await __wbg_load(await input, imports);

return finalizeInit(instance, module);
return __wbg_finalize_init(instance, module);
}

export { initSync }
export default init;
export default __wbg_init;
Binary file modified wasm/pkg/colamone_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/pkg/colamone_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export function __wbg_set_result_from(a: number, b: number): void;
export function __wbg_get_result_to(a: number): number;
export function __wbg_set_result_to(a: number, b: number): void;
export function think_ai(a: number, b: number, c: number, d: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_malloc(a: number, b: number): number;
18 changes: 0 additions & 18 deletions wasm/pkg/package.json

This file was deleted.

0 comments on commit 240c04b

Please sign in to comment.