웹어셈블리 시작하기 (Emscripten)
1. Emscripten 설치
설치 OS = MacOS
# Emscripten SDK를 깃을 통해 다운로드 받고
git clone https://github.com/juj/emsdk.git
# 다운로드 받은 디렉토리로 이동
cd emsdk
# 최신 버전으로 풀 받고
git pull
# 최신 버전으로 설치
./emsdk install latest
######## 설치가 완료된 후에 #########3
# emsdk 최신버전 활성화
./emsdk activate latest
# 최신 SDK 활성화
source ./emsdk_env.sh
설치가 완려되었으면 현재폴더에서 "emcc -v" 명령어를 쳐서 버전 정보가 나온다면 설치성공
2. 테스트 C 파일 생성하고 JS파일로 전환
emsdk/tests/ 경로에 helloWorld.c 파일을 생성
#include <stdio.h>
int main() {
printf("hello, world!\n");
return 0;
}
아래명령어를 통해 c파일을 js파일로 변환
emcc tests/helloWorld.c -o tests/helloWorld.js
JS파일이 생성된 폴더로 가본다면 WASM파일도 같이 생성됬을것이다.
마지막으로 node명령어를 통해 실행한다면 Hello World!가 출력되는것을 확인할 수 있다.
Emscripten 옵션
emscripten.org/docs/tools_reference/emcc.html
Emscripten Compiler Frontend (emcc) — Emscripten 2.0.15 documentation
To see the full list of Clang options supported on the version of Clang used by Emscripten, run clang --help. --post-js [link] Like --pre-js, but emits a file after the emitted code. --extern-pre-js [link] Specify a file whose contents are prepended to the
emscripten.org
Closure-Compiler 옵션
github.com/google/closure-compiler/wiki/Flags-and-Options
google/closure-compiler
A JavaScript checker and optimizer. Contribute to google/closure-compiler development by creating an account on GitHub.
github.com