이화물 부하 명령은 Rust로 작성된 클라이언트 측 웹 응용 프로그램을 쉽고 편리하게 만들 수 있도록 목표로합니다.
이 소프트웨어는이 훌륭한 사람들 덕분에 당신에게 가져 왔습니다.
감사합니다!
현재 다음과 같은 기능을 지원합니다.
cargo web build Rust의 세 가지 웹 백엔드 중 하나를 사용하여 프로젝트를 구축 할 것입니다.--target=wasm32-unknown-unknown ; 기본값)--target=wasm32-unknown-emscripten )--target=asmjs-unknown-emscripten )cargo web check 프로젝트를 입력합니다cargo web test - 테스트를 실행합니다.--nodejs 통과 할 때)cargo web start 프로젝트를 구축하고 내장 된 웹 서버를 시작하며 필요한 경우 지속적으로 재건됩니다. --auto-reload 로 자동 재 장전을 지원합니다.cargo web deploy - 프로젝트를 구축하고 필요한 모든 파일을 방출하여 통계적으로 쉽게 제공 할 수 있습니다.rustup 통해 관련 Rust Target을 자동으로 설치합니다 프로젝트에서 JavaScript 세계와 상호 작용하려면 STDWeb 상자를 확인하는 것이 좋습니다. (실제로 cargo-web 는 Rust의 기본 WebAssembly 백엔드에서 stdweb 의 js! 매크로를 사용할 수있게합니다.)
$ cargo install cargo-web
업그레이드하려면 :
$ cargo install --force cargo-web
또는 $ cargo build --release 사용하여 $ 경로에 배치하십시오.
Linux에서는 OpenSSL을 찾을 수 없다는 메시지로 설치가 실패 할 수 있으며,이 경우 배포 리포지토리에서 OpenSSL 용 -dev 패키지를 설치해야 할 가능성이 높습니다. (우분투에서는 libssl-dev 라고합니다.)
Web.toml cargo-web 에는 자체 구성 파일이있어 cargo 의 Cargo.toml 옆에 넣을 수 있습니다.
다음은 지원되는 모든 키를 보여주는 예제 구성입니다.
# The default value of `--target` used when building this crate
# in cases where it's not specified on the command line.
default-target = " wasm32-unknown-unknown "
# This will prepend a given JavaScript file to the resulting `.js` artifact.
# You can put any initialization code here which you'd like to have executed
# when your `.js` file first loads.
#
# This accepts either a string (as shown here), or an array of strings,
# in which case it will prepend all of the specified files in their
# order of appearance.
prepend-js = " src/runtime.js "
[ cargo-web ]
# Asserts the minimum required version of `cargo-web` necessary
# to compile this crate; supported since 0.6.0.
minimum-version = " 0.6.0 "
# These will only take effect on *-emscripten targets.
[ target . emscripten ]
# You can have a target-specific `prepend-js` key.
prepend-js = " src/emscripten_runtime.js "
# This will enable Emscripten's SDL2 port. Consult Emscripten's documentation
# for more details.
link-args = [ " -s " , " USE_SDL=2 " ]
# You can also specify the target by its full name.
[ target . wasm32-unknown-unknown ]
prepend-js = " src/native_runtime.js " Web.toml 있는 외부 상자를 사용하는 경우 cargo-web 로드 되어 사용합니다.
Web.toml 에 관한 몇 가지 제한 사항 :
prepend-js 키를 겹치는 것은 없습니다. 단일 글로벌 prepend-js 또는 여러 표적 당 표적 당을 정의 할 수 있습니다.link-args 현재 어떤 공간도 가지고 있지 않습니다.cargo-web 여러 상자에서 Web.toml 파일을 처리하는 순서는 결정 론적이지만 지정되지 않습니다. 이것은 당신이 어떤 식 으로든이 순서에 의존해서는 안된다는 것을 의미합니다. cargo web start 실행하거나 cargo web deploy 실행할 때 배포 할 때 제공하려는 정적 파일은 상자의 루트에있는 static 이라는 디렉토리에 넣을 수 있습니다. 기본적으로 정적 인공물이 필요하지 않습니다. index.html 파일이 누락 된 경우 자동으로 생성됩니다. 물론 자신의 static/index.html 파일을 배치 할 수 있습니다.이 경우 자동 생성 된 것 대신 사용됩니다.
cargo-web 감지 컴파일 중에 프로젝트가 cargo-web 로 구축되고 있음을 감지하려면 COMPILING_UNDER_CARGO_WEB 환경 변수를 확인할 수 있으며, 이는 1 으로 설정됩니다.
cargo-web 사용 다음 스크립트를 사용하여 최신 cargo-web 다운로드하여 설치할 수 있습니다.
CARGO_WEB_RELEASE= $( curl -L -s -H ' Accept: application/json ' https://github.com/koute/cargo-web/releases/latest )
CARGO_WEB_VERSION= $( echo $CARGO_WEB_RELEASE | sed -e ' s/.*"tag_name":"([^"]*)".*/1/ ' )
if [ " $( uname -s ) " == " Darwin " ] ; then
CARGO_WEB_HOST_TRIPLE= " x86_64-apple-darwin "
else
CARGO_WEB_HOST_TRIPLE= " x86_64-unknown-linux-gnu "
fi
CARGO_WEB_URL= " https://github.com/koute/cargo-web/releases/download/ $CARGO_WEB_VERSION /cargo-web- $CARGO_WEB_HOST_TRIPLE .gz "
echo " Downloading cargo-web from: $CARGO_WEB_URL "
curl -L $CARGO_WEB_URL | gzip -d > cargo-web
chmod +x cargo-web
mkdir -p ~ /.cargo/bin
mv cargo-web ~ /.cargo/bin 기본적으로 cargo web test 헤드리스 크롬 하에서 테스트를 실행합니다. Travis에서 이것을 사용할 수 있으려면 .travis.yml 에 이와 같은 것을 추가해야합니다.
addons :
chrome : stable wasm32-unknown-unknown -ly) 기본적으로 프로젝트를 구축 할 때 cargo-web 독립형 런타임 런타임을 생성합니다. 이것이 의미하는 바는 생성 된 .js 파일을 <script> 태그 내부에 즉시 넣거나 수동으로로드하거나 추가 작업을 수행하지 않고도 Node.js로 시작할 수 있다는 것입니다. 그러나 사용자 정의 가능성과 관련하여 제한합니다.
모듈로드 방법을 조금 더 제어하려면 --runtime library-es6 옵션을 사용하여 cargo-web 비 스탠다 론, 라이브러리와 같은 모듈을 생성하도록 지시 할 수 있습니다. 이렇게하면 다음 인터페이스로 공장 기능을 내보내는 .js 파일이 발생합니다.
export default function ( ) {
return {
imports : { ... } ,
initialize : function ( instance ) { ... }
} ;
} 여기에서 webassembly 모듈을 직접 인스턴스화해야합니다. 이 경우 가져 오기로 가져 와서 imports 통과 한 다음 즉시 인스턴스화 직후에 initialize 호출해야합니다.
예를 들어, cargo-web 에서 생성 한 모듈을 my-module.mjs 및 my-module.wasm 으로 지정할 것이라고 가정하면 Node.js에서 이와 같이 인스턴스화 할 수 있습니다.
import fs from "fs" ;
import factory from "my-module.mjs" ;
// We read in the `.wasm` module.
const bytecode = fs . readFileSync ( "my-module.wasm" ) ;
const wasm = new WebAssembly . Module ( bytecode ) ;
// We instantiate it.
const instance = factory ( ) ;
const compiled = new WebAssembly . Instance ( wasm , instance . imports ) ;
// This will initialize the module and call your `main`, if you have one.
const exports = instance . initialize ( compiled ) ;
// In the object it returns you can find any functions which
// you've exported with `stdweb`'s `#[js_export]` macro.
console . log ( exports . add ( 1 , 2 ) ) ; 그런 다음 node --experimental-modules run.mjs 로 실행할 수 있습니다.
이는 사용자 정의 URL에서 .wasm 파일을로드하려고하거나 출력을 JavaScript Bundler와 통합하거나 모듈을 직접로드 해야하는 다른 것과 통합하려는 경우 유용합니다.
0.6.26--no-default-features 플래그가 고정되었습니다mime-guess Crate는 이제 임베디드 웹 서버에 의해 마임 유형을 추측하는 데 사용됩니다.0.6.25cargo web start 이제 프로젝트 파일이 빠르게 연속적으로 수정 될 때 불필요한 재건을 트리거하지 않도록합니다.0.6.24[target.'cfg(...)'.dependencies] 이 올바르게 지원됩니다cfg(cargo_web) 사용하여 cargo-web 에서 상자가 편집 될 때마다 감지 할 수 있습니다.target/wasm32-unknown-unknown/*/deps/*.wasm 이제 무시됩니다. 이것은 의존성으로 인해 cargo-web cdylib .wasm 아티팩트가 생성되는 것을 막아야합니다.cargo-web 이제 structopt 기반 인터페이스를 통해 라이브러리로 제공됩니다.0.6.23cargo web checkwasm32-unknown-unknown 대상이 이제 기본값입니다0.6.22deploy 서브 명령은 이제 -o / --output 매개 변수를 사용하여 배포 할 위치를 알 수 있습니다.Access-Control-Allow-Origin: * 는 이제 항상 임베디드 웹 서버가 전송합니다.wasm32-unknown-unknown 에 대한 디버그 빌드는 최근에 충분한 stdweb 사용되는 경우 지원됩니다.0.6.211.38.19 로 업데이트되었습니다. EMScripten 기반 목표는 이제 밤에 다시 작동해야합니다wasm32-unknown-unknown 의 생성 된 JS 스 니펫 및 수입은 이제 정렬되었습니다.wasm32-unknown-unknown 에서는 정말 오래된 야간과의 호환성이 제거되었습니다0.6.20cargo install 통한 설치는 이제 다시 작동해야합니다deploy 당황해서는 안됩니다.0.6.19cargo install 컴파일해야합니다.1.26.2 입니다0.6.18index.html 더 이상 DocType 전에 NewLine이 없습니다.0.6.171.25.0 입니다0.6.16wasm32-unknown-unknown 의 런타임은 이제 WebAssembly.instantiateStreaming 사용하여 사용합니다wasm32-unknown-unknown Target에 대해 지원됩니다.cargo-web 의 출력이 리디렉션되면 색상 코드가 더 이상 방출되지 않습니다.어느 쪽에도 라이센스가 부여되었습니다
귀하의 선택에.
귀하가 명시 적으로 명시 적으로 명시하지 않는 한, APACHE-2.0 라이센스에 정의 된대로 귀하가 작업에 포함시키기 위해 의도적으로 제출 된 모든 기부금은 추가 이용 약관이나 조건없이 위와 같이 이중 라이센스를받습니다.