WebAssembly multiple module

카테고리 없음 2020. 5. 14. 15:27

WebAssembly 아직은 너무 생소하다...

emcc 커맨드를 통해 컴파일한 결과물... 예를 들면,

aaa.js bbb.js ccc.js 

 

이 녀석들을 열어보면...

그럼... 내가 여러개의 웹어셈블 코드를 사용한다 치자...

전부 다 Module 이네? 어떤걸로 구분하지...?

 

실제로 아직 웹어셈블을 이용하여 개발을 해본적은 없기에 이 방법이 맞는지는 모르겠다.

 

1. compile

1
2
3
4
5
6
7
8
//example [aaa]
emcc aaa.c -o aaa.js -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'-s EXPORT_NAME="'custom_1'" -s MODULARIZE=1
 
//example [bbb]
emcc bbb.c -o bbb.js -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'-s EXPORT_NAME="'custom_2'" -s MODULARIZE=1
 
//example [ccc]
emcc ccc.c -o ccc.js -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'-s EXPORT_NAME="'custom_3'" -s MODULARIZE=1
cs

 

2. javascript sample code

1
2
3
4
5
6
7
8
9
10
11
custom_1().then(function(Module){
        Module.ccall(...............);
});
 
custom_2().then(function(Module){
        Module.ccall(...............);
});
 
custom_3().then(function(Module){
        Module.ccall(...............);
});
cs

 

EXPORT_NAME 으로 지정한 custom_1, custom_2, custom_3 으로 호출했다.

솔직히 이게 맞는 방법인진 모르겠다..............