Skip to content

Commit

Permalink
Merge pull request #26 from kamakiri01/drop-typings-d-ts
Browse files Browse the repository at this point in the history
build without include typings d.ts
  • Loading branch information
kamakiri01 authored Jul 3, 2023
2 parents 57c1e12 + 762625e commit 0a83692
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 22 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# ChangeLog

# 0.0.3
- release
## 0.0.4
- Reorganized type definition dependencies

## 0.0.3
- Release
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qulacs-wasm",
"version": "0.0.3",
"version": "0.0.4",
"description": "Qulacs WebAssembly version",
"main": "lib/bundle/index.js",
"scripts": {
Expand All @@ -25,8 +25,8 @@
"build:emscripten:em++:bundle": "em++ -O1 -s SINGLE_FILE=1 -I ./submodules/boost -I ./submodules/qulacs/include -L ./submodules/qulacs/lib -o ./lib-cpp/bundle/module.js ./src-cpp/QulacsWasmModule.cpp -lvqcsim_static -lcppsim_static -lcsim_static -s MODULARIZE=1 -s 'EXPORT_NAME=\"ModuleQulacsWasm\"' --bind -s DISABLE_EXCEPTION_CATCHING=0 -s EXPORTED_RUNTIME_METHODS=addFunction,removeFunction,ccall,cwrap,dyncall -s ALLOW_TABLE_GROWTH -s EXTRA_EXPORTED_RUNTIME_METHODS=['dynCall','getValue','setValue'] -s ALLOW_MEMORY_GROWTH",
"build:emscripten:em++:nobundle": "em++ -O1 -I ./submodules/boost -I ./submodules/qulacs/include -L ./submodules/qulacs/lib -o ./lib-cpp/nobundle/module.js ./src-cpp/QulacsWasmModule.cpp -lvqcsim_static -lcppsim_static -lcsim_static -s MODULARIZE=1 -s 'EXPORT_NAME=\"ModuleQulacsWasm\"' --bind -s DISABLE_EXCEPTION_CATCHING=0 -s EXPORTED_RUNTIME_METHODS=addFunction,removeFunction,ccall,cwrap,dyncall -s ALLOW_TABLE_GROWTH -s EXTRA_EXPORTED_RUNTIME_METHODS=['dynCall','getValue','setValue'] -s ALLOW_MEMORY_GROWTH",
"build:emscripten:cp": "npm run build:emscripten:cp:bundle && npm run build:emscripten:cp:nobundle",
"build:emscripten:cp:bundle": "cpx \"./lib-cpp/bundle/**\" \"./lib/bundle/wasm/\" --clean",
"build:emscripten:cp:nobundle": "cpx \"./lib-cpp/nobundle/**\" \"./lib/nobundle/wasm/\" --clean",
"build:emscripten:cp:bundle": "cpx \"./lib-cpp/bundle/**\" \"./lib/bundle/wasm/\"",
"build:emscripten:cp:nobundle": "cpx \"./lib-cpp/nobundle/**\" \"./lib/nobundle/wasm/\"",
"test": "jest && npm run lint",
"lint": "eslint \"./src-ts/**/*.ts\" \"./test/**/*.ts\""
},
Expand Down
5 changes: 2 additions & 3 deletions src-cpp/QulacsWasmModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ EMSCRIPTEN_BINDINGS(Bindings) {
.function("multiply_elementwise_function_wrapper", emscripten::optional_override([](QuantumState& self, intptr_t funcPtr) {
// JSのfuncPtr先の関数をC++の型でラップする
std::function<CPPCTYPE(ITYPE)> func = [funcPtr](ITYPE num) -> CPPCTYPE {
int castedNum = (int) num;
double complexArr[2]; // 戻り値のcomplex要素を格納するメモリを確保する
QuantumStateMultiplyElementwiseFunctionWrapper(funcPtr, castedNum, complexArr); // メモリにfuncPtrの実行結果を書き込む
QuantumStateMultiplyElementwiseFunctionWrapper(funcPtr, num, complexArr); // メモリにfuncPtrの実行結果を書き込む
double real = complexArr[0];
double imag = complexArr[1];
std::complex<double> c(real, imag);
Expand Down Expand Up @@ -743,7 +742,7 @@ EMSCRIPTEN_BINDINGS(Bindings) {
auto size = list.size();
int arr[size];
for (int i = 0; i < size; i++) {
arr[i] = (int)list[i];
arr[i] = list[i];
}
return AdaptiveWrapper(funcPtr, arr, size);
};
Expand Down
2 changes: 1 addition & 1 deletion src-cpp/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ emscripten::EM_VAL transpaleITYPEVecToJSArray(const std::vector<ITYPE> &vec) {
int size = vec.size();
int arr[size];
for (int i = 0; i < size; i++) {
arr[i] = (int) vec[i]; // NOTE: long long intをintに丸めている。JSで (un)signed long long intを取得する方法を検討
arr[i] = vec[i];
}
return convertIntArrayToJSArray(arr, size);
}
Expand Down
1 change: 1 addition & 0 deletions src-ts/main/emsciptenModule/QulacsWasmModule.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { EmscriptenWasm } from "../../wasm/emscriptem-types";
export interface QulacsWasmModule extends EmscriptenWasm.Module {
//QuantumState: QuantumStateI; // NOTE: applyModuleのObject.keysで取得するため、メンバを型では直接参照しない。そのため、ここでメンバを定義する必要はない
getExceptionMessage(exceptionPtr: number): string;
Expand Down
4 changes: 3 additions & 1 deletion src-ts/main/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ModuleQulacsWasm = require("../wasm/module.js");
import ModuleQulacsWasm from "../wasm/module";
import { EmscriptenWasm } from "../wasm/emscriptem-types";
import { QulacsWasmModule } from "./emsciptenModule/QulacsWasmModule";
import { applyModule } from "./instance";

Expand Down Expand Up @@ -30,6 +31,7 @@ function _initQulacsFromModule(compiledModule: WebAssembly.Module): Promise<Qula
successCallback(instance);
})
.catch(e => reject(e));
return undefined!; // NOTE: @types/emscriptenでは不要なnon-null assertionかもしれない
}
ModuleQulacsWasm({ instantiateWasm: onInstantiateWasm })
.then((emscriptenModule: EmscriptenWasm.Module) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// reference from https://github.com/jamsinclair/jSquash/blob/db110f3adb463615e9022bd62b124c87ae2c8bc0/packages/jpeg/emscriptem-types.d.ts

// These types roughly model the object that the JS files generated by Emscripten define. Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts and turned into a type definition rather than a global to support our way of using Emscripten.
// TODO(@surma): Upstream this?
declare namespace EmscriptenWasm {

// eslint-disable-next-line @typescript-eslint/no-namespace
export declare namespace EmscriptenWasm {
type ModuleFactory<T extends Module = Module> = (
moduleOverrides?: ModuleOpts,
) => Promise<T>;
Expand Down Expand Up @@ -30,6 +31,7 @@ declare namespace EmscriptenWasm {
preInit: { (): void }[];
preRun: { (): void }[];
postRun: { (): void }[];
// eslint-disable-next-line no-undef
preinitializedWebGLContext: WebGLRenderingContext;
noInitialRun: boolean;
noExitRuntime: boolean;
Expand Down
6 changes: 6 additions & 0 deletions src-ts/wasm/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// NOTE: このファイルはtscビルドを通す型整合性のためだけに利用し、publishには含まない。このファイルはnpm run build終了時点でemscriptenのmodule.jsに上書きされる
import {EmscriptenWasm} from "./emscriptem-types";
import { QulacsWasmModule } from "../main/emsciptenModule/QulacsWasmModule";

declare const ModuleQulacsWasm: EmscriptenWasm.ModuleFactory<QulacsWasmModule>;
export = ModuleQulacsWasm;
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"./typings/ModuleQulacsWasm.d.ts",
"./typings/emscriptem-types.d.ts"
],
"include": [
"./src-ts/**/*"
]
Expand Down
6 changes: 0 additions & 6 deletions typings/ModuleQulacsWasm.d.ts

This file was deleted.

0 comments on commit 0a83692

Please sign in to comment.