├── rust-toolchain ├── bootstrap.js ├── index.js ├── .travis.yml ├── index.html ├── tests └── tests.rs ├── .gitignore ├── benches └── benches.rs ├── webpack.config.js ├── package.json ├── LICENSE-MIT ├── src └── lib.rs ├── Cargo.toml ├── README.md ├── CONTRIBUTING.md ├── ci └── script.sh └── LICENSE-APACHE /rust-toolchain: -------------------------------------------------------------------------------- 1 | nightly 2 | -------------------------------------------------------------------------------- /bootstrap.js: -------------------------------------------------------------------------------- 1 | import("./index").then( 2 | () => console.log("Loaded."), 3 | error => console.error(error) 4 | ); 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { Counter } from "./{{crate_name}}"; 2 | 3 | const c = Counter.new(); 4 | console.log(c.increment()); 5 | console.log(c.increment()); 6 | console.log(c.increment()); 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | cache: cargo 3 | 4 | rust: 5 | - nightly 6 | 7 | env: 8 | matrix: 9 | - JOB="wasm" 10 | - JOB="build" 11 | - JOB="test" 12 | - JOB="bench" 13 | 14 | script: 15 | - ./ci/script.sh 16 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/tests.rs: -------------------------------------------------------------------------------- 1 | extern crate {{crate_name}}; 2 | 3 | use {{crate_name}}::Counter; 4 | 5 | #[test] 6 | fn tests_in_the_tests_dir_work() { 7 | let mut c = Counter::new(); 8 | assert_eq!(c.increment(), 0); 9 | assert_eq!(c.increment(), 1); 10 | assert_eq!(c.increment(), 2); 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | .crates.toml 5 | /node_modules 6 | package-lock.json 7 | /dist 8 | 9 | # Local install of wasm-bindgen. 10 | bin/wasm-bindgen 11 | bin/wasm2es6js 12 | 13 | # Generated by wasm-bindgen. 14 | {{crate_name}}.d.ts 15 | {{crate_name}}.js 16 | {{crate_name}}_bg.wasm 17 | -------------------------------------------------------------------------------- /benches/benches.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | extern crate {{crate_name}}; 4 | extern crate test; 5 | 6 | use {{crate_name}}::Counter; 7 | 8 | #[bench] 9 | fn benches_in_the_benches_dir_work(b: &mut test::Bencher) { 10 | let mut c = Counter::new(); 11 | b.iter(|| { 12 | c.increment(); 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const RustPlugin = require("rust-plugin"); 3 | 4 | module.exports = { 5 | entry: "./bootstrap.js", 6 | output: { 7 | path: path.resolve(__dirname, "dist"), 8 | filename: "bootstrap.js", 9 | }, 10 | mode: "development", 11 | plugins: [ 12 | new RustPlugin() 13 | ] 14 | }; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "build": "npm run build:wasm && npm run build:webpack && npm run build:final", 4 | "build:wasm": "JOB=wasm ./ci/script.sh", 5 | "build:webpack": "webpack", 6 | "build:final": "JOB=final ./ci/script.sh", 7 | "serve": "webpack-dev-server" 8 | }, 9 | "devDependencies": { 10 | "webpack": "^4.16.2", 11 | "webpack-cli": "^3.1.0", 12 | "webpack-dev-server": "^3.1.5", 13 | "rust-plugin": "0.0.5" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! My awesome Rust and WebAssembly project! 2 | 3 | #![feature(use_extern_macros, wasm_custom_section, wasm_import_module)] 4 | 5 | #[macro_use] 6 | extern crate cfg_if; 7 | 8 | cfg_if! { 9 | // When the `console_error_panic_hook` feature is enabled, we can call the 10 | // `set_panic_hook` function to get better error messages if we ever panic. 11 | if #[cfg(feature = "console_error_panic_hook")] { 12 | extern crate console_error_panic_hook; 13 | use console_error_panic_hook::set_once as set_panic_hook; 14 | } else { 15 | #[inline] 16 | fn set_panic_hook() {} 17 | } 18 | } 19 | 20 | cfg_if! { 21 | // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global 22 | // allocator. 23 | if #[cfg(feature = "wee_alloc")] { 24 | extern crate wee_alloc; 25 | #[global_allocator] 26 | static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; 27 | } 28 | } 29 | 30 | extern crate wasm_bindgen; 31 | use wasm_bindgen::prelude::*; 32 | 33 | /// My publicly exported type! 34 | #[wasm_bindgen] 35 | pub struct Counter { 36 | count: u32, 37 | } 38 | 39 | /// My publicly exported methods! 40 | #[wasm_bindgen] 41 | impl Counter { 42 | pub fn new() -> Counter { 43 | set_panic_hook(); 44 | Counter { count: 0 } 45 | } 46 | 47 | pub fn increment(&mut self) -> u32 { 48 | let x = self.count; 49 | self.count += 1; 50 | x 51 | } 52 | } 53 | 54 | #[cfg(test)] 55 | mod tests { 56 | #[test] 57 | fn tests_inside_the_crate_work() { 58 | assert_eq!(2 + 2, 4); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["{{authors}}"] 3 | categories = ["wasm"] 4 | description = "My super awesome Rust and WebAssembly project!" 5 | license = "Apache-2.0/MIT" 6 | name = "{{project-name}}" 7 | readme = "./README.md" 8 | repository = "https://github.com/rustwasm/{{project-name}}" 9 | version = "0.1.0" 10 | 11 | [badges] 12 | # Change this to your project's GitHub repo! 13 | travis-ci = { repository = "rustwasm/rust_wasm_template" } 14 | 15 | [lib] 16 | crate-type = [ 17 | # Build a cdylib to make a `.wasm` library. 18 | "cdylib", 19 | # Build an rlib for testing and benching. 20 | "rlib" 21 | ] 22 | 23 | [dependencies] 24 | cfg-if = "0.1.2" 25 | wasm-bindgen = "0.2.12" 26 | 27 | # The `console_error_panic_hook` crate provides better debugging of panics by 28 | # logging them with `console.error`. This is great for development, but requires 29 | # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for 30 | # code size when deploying. 31 | console_error_panic_hook = { version = "0.1.1", optional = true } 32 | 33 | # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size 34 | # compared to the default allocator's ~10K. It is slower than the default 35 | # allocator, however. 36 | wee_alloc = { version = "0.4.1", optional = true } 37 | 38 | [features] 39 | default-features = ["console_error_panic_hook", "wee_alloc"] 40 | 41 | [profile.release] 42 | # Enable this option for better time and size profiling. 43 | # debug = true 44 | 45 | # Optimize for small code size, rather than speed. 46 | opt-level = "s" 47 | 48 | # Always enable link-time optimizations to shrink binary sizes. 49 | lto = true 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **DEPRECATED**: Use rustwasm/wasm-pack-template for libraries and rustwasm/rust-webpack-template for webapps with webpack. 4 | 5 | # Rust 🦀 and WebAssembly 🕸 Template 🏗 6 | 7 | [![Build Status](https://travis-ci.org/rustwasm/rust_wasm_template.svg?branch=master)](https://travis-ci.org/rustwasm/rust_wasm_template) 8 | 9 | This is a template to jump-start your Rust and WebAssembly project and let you 10 | hit the ground running. 11 | 12 | ## 🛍 What's Inside? 13 | 14 | * ✔ The latest [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for 15 | light and seamless bidirectional communication between Rust and 16 | JavaScript. Import JavaScript things into Rust and export Rust things to 17 | JavaScript. 18 | 19 | * ✔ Boilerplate for builds, optimizing, and post-processing: 20 | 21 | * ✔ Generates the JS interface to your `.wasm` binary with the appropriate 22 | `wasm-bindgen` invocation. 23 | 24 | * ✔ Runs [`wasm-opt`](https://github.com/WebAssembly/binaryen) to shrink the 25 | `.wasm` binary's code size and also speed it up at runtime. 26 | 27 | * ✔ Bundles your JS with [Webpack](https://webpack.js.org/). 28 | 29 | * ✔ Serve your `.wasm` and JS locally with [Webpack's 30 | dev-server](https://github.com/webpack/webpack-dev-server/). 31 | 32 | * ✔ Better debugging with [Rust panics forwarded to 33 | `console.error`](https://github.com/rustwasm/console_error_panic_hook). 34 | 35 | * ✔ Optionally use [`wee_alloc`](https://github.com/rustwasm/wee_alloc) as the 36 | global allocator, to help keep your code size footprint small. 37 | 38 | * ✔ Boilerplate for writing `#[test]`s and `#[bench]`es for the native target. 39 | 40 | * ✔ Travis CI integration already set up. Make sure you never break your tests 41 | or your WebAssembly builds. 42 | 43 | ## 🤸 Using this Template 44 | 45 | First, install `cargo-generate`: 46 | 47 | ``` 48 | cargo install cargo-generate 49 | ``` 50 | 51 | Second, generate a new project with this repository as a template: 52 | 53 | ``` 54 | cargo-generate --git https://github.com/rustwasm/rust_wasm_template.git 55 | ``` 56 | 57 | Answer the prompts and then you should be good to go! Check out your new 58 | [`CONTRIBUTING.md`](./CONTRIBUTING.md) for details on building and project 59 | organization. 60 | 61 | ### Enabling Travis CI 62 | 63 | The Travis CI configuration is 100% pre-configured, and all you need to do is 64 | [enable CI for the repo on your profile page](https://travis-ci.org/profile/). 65 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | - [Code of Conduct](#code-of-conduct) 4 | - [Overview](#overview) 5 | - [Building](#building) 6 | - [Native](#native) 7 | - [Just the WebAssembly](#just-the-webassembly) 8 | - [WebAssembly and JavaScript Bundle](#webassembly-and-javascript-bundle) 9 | - [Cargo Features](#cargo-features) 10 | - [Serving Locally with Webpack](#serving-locally-with-webpack) 11 | - [Testing](#testing) 12 | - [Benchmarking](#benchmarking) 13 | - [Code Formatting](#code-formatting) 14 | 15 | ## Code of Conduct 16 | 17 | We abide by the [Rust Code of 18 | Conduct](https://www.rust-lang.org/en-US/conduct.html) and ask that you do as 19 | well. 20 | 21 | ## Overview 22 | 23 | * `src/lib.rs`: Main entry point for the Rust crate. 24 | 25 | * `index.html`: Root HTML page that loads the JS and Wasm. 26 | 27 | * `index.js`: Root JS module, imports the `wasm-bindgen`-generated JS interface 28 | to the Rust's Wasm, and transitively loads the Wasm itself. 29 | 30 | * `tests/`: Rust tests for native code. 31 | 32 | * `benches/`: Rust benchmarks for native code. 33 | 34 | * `webpack.config.js`: Webpack configuration. 35 | 36 | * `ci/`: Continuous integration scripts. 37 | 38 | ## Building 39 | 40 | ### Native 41 | 42 | To build the crate for the native target, run 43 | 44 | ``` 45 | cargo build 46 | ``` 47 | 48 | or 49 | 50 | ``` 51 | cargo build --release 52 | ``` 53 | 54 | ### Just the WebAssembly 55 | 56 | To build just the `.wasm` binary, run 57 | 58 | ``` 59 | cargo build --target wasm32-unknown-unknown 60 | ``` 61 | 62 | or 63 | 64 | ``` 65 | cargo build --target wasm32-unknown-unknown --release 66 | ``` 67 | 68 | ### WebAssembly and JavaScript Bundle 69 | 70 | First, ensure that you've installed Webpack locally by running this command 71 | within the repository: 72 | 73 | ``` 74 | npm install 75 | ``` 76 | 77 | Then, to build the optimized WebAssembly, the `wasm-bindgen` JS interface to it, 78 | and the JavaScript bundle using the JS interface, run: 79 | 80 | ``` 81 | npm run build 82 | ``` 83 | 84 | ### Cargo Features 85 | 86 | * `wee_alloc`: Enable using [`wee_alloc`](https://github.com/rustwasm/wee_alloc) 87 | as the global allocator. This trades allocation speed for smaller code size. 88 | 89 | * `console_error_panic_hook`: Enable better debugging of panics by printing 90 | error messages in browser devtools with `console.error`. 91 | 92 | ## Serving Locally with Webpack 93 | 94 | Ensure that you have installed Webpack and its development server by running 95 | this command within the repository: 96 | 97 | ``` 98 | npm install 99 | ``` 100 | 101 | After that, you can start a local server on 102 | [http://localhost:8080](http://localhost:8080) by running this command: 103 | 104 | ``` 105 | npm run serve 106 | ``` 107 | 108 | ## Testing 109 | 110 | There are integration tests in the `tests/` directory, and unit tests in 111 | `#[cfg(test)]` modules within the crate itself. 112 | 113 | To run all the tests, run 114 | 115 | ``` 116 | cargo test 117 | ``` 118 | 119 | ## Benchmarking 120 | 121 | Benchmarks live within the `benches/` directory. 122 | 123 | To run all benchmarks, run 124 | 125 | ``` 126 | cargo bench 127 | ``` 128 | 129 | ## Code Formatting 130 | 131 | Ensure that you have the `rustfmt-preview` component installed in `rustup`: 132 | 133 | ``` 134 | rustup component add rustfmt-preview 135 | ``` 136 | 137 | To format all of the code in the crate, run 138 | 139 | ``` 140 | cargo fmt 141 | ``` 142 | -------------------------------------------------------------------------------- /ci/script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | cd "$(dirname "$0")/.." 5 | 6 | function main { 7 | ensure_template_filled_out 8 | 9 | case "$JOB" in 10 | "build") 11 | do_build 12 | ;; 13 | 14 | "test") 15 | do_test 16 | ;; 17 | 18 | "bench") 19 | do_bench 20 | ;; 21 | 22 | "wasm") 23 | do_wasm 24 | ;; 25 | 26 | "final") 27 | do_final 28 | ;; 29 | 30 | *) 31 | echo "Error: unknown \$JOB = $JOB" 32 | exit 1 33 | ;; 34 | esac 35 | } 36 | 37 | function do_build { 38 | header 'Building' 39 | 40 | # With no default features. 41 | logged cargo \ 42 | cargo +nightly build --no-default-features 43 | logged cargo \ 44 | cargo +nightly build --release --no-default-features 45 | 46 | # With just the `wee_alloc` feature. 47 | logged cargo \ 48 | cargo +nightly build --no-default-features --features wee_alloc 49 | logged cargo \ 50 | cargo +nightly build --release --no-default-features --features wee_alloc 51 | 52 | # With just the `console_error_panic_hook` feature. 53 | logged cargo \ 54 | cargo +nightly build --no-default-features --features console_error_panic_hook 55 | logged cargo \ 56 | cargo +nightly build --release --no-default-features --features console_error_panic_hook 57 | 58 | # With default features. 59 | logged cargo \ 60 | cargo +nightly build 61 | logged cargo \ 62 | cargo +nightly build --release 63 | } 64 | 65 | function do_test { 66 | header 'Testing' 67 | 68 | # With no default features. 69 | logged cargo \ 70 | cargo +nightly test --no-default-features 71 | logged cargo \ 72 | cargo +nightly test --release --no-default-features 73 | 74 | # With just the `wee_alloc` feature. 75 | logged cargo \ 76 | cargo +nightly test --no-default-features --features wee_alloc 77 | logged cargo \ 78 | cargo +nightly test --release --no-default-features --features wee_alloc 79 | 80 | # With just the `console_error_panic_hook` feature. 81 | logged cargo \ 82 | cargo +nightly test --no-default-features --features console_error_panic_hook 83 | logged cargo \ 84 | cargo +nightly test --release --no-default-features --features console_error_panic_hook 85 | 86 | # With default features. 87 | logged cargo \ 88 | cargo +nightly test 89 | logged cargo \ 90 | cargo +nightly test --release 91 | } 92 | 93 | function do_bench { 94 | header 'Benchmarking' 95 | logged cargo \ 96 | cargo +nightly bench 97 | } 98 | 99 | function do_wasm { 100 | header 'Updating rust nightly and installing the `wasm32-unknown-unknown` target.' 101 | 102 | logged rustup \ 103 | rustup update nightly 104 | logged rustup \ 105 | rustup target add wasm32-unknown-unknown --toolchain nightly 106 | 107 | header 'Building for `wasm32-unknown-unknown` target.' 108 | logged cargo \ 109 | cargo +nightly build \ 110 | --release \ 111 | --target wasm32-unknown-unknown 112 | 113 | header 'Installing wasm-bindgen locally' 114 | ensure_wasm_bindgen_installed 115 | 116 | header 'Running wasm-bindgen' 117 | local target_wasm_file=$(ls ./target/wasm32-unknown-unknown/release/*.wasm) 118 | logged wasm-bindgen \ 119 | ./bin/wasm-bindgen \ 120 | --out-dir . \ 121 | "$target_wasm_file" 122 | } 123 | 124 | function do_final { 125 | local local_wasm_file=$(ls dist/*.wasm) 126 | 127 | header 'Final `.wasm` Size' 128 | wc -c "$local_wasm_file" 129 | } 130 | 131 | function get_wasm_bindgen_version { 132 | # * Find the wasm-bindgen dependency in Cargo.toml 133 | # 134 | # * Split on the '=' in 'wasm-bindgen = "X.Y.Z"' and take the version number 135 | # on the right hand side. 136 | # 137 | # * Replace the double quotes with spaces. 138 | # 139 | # * Trim whitespace. 140 | grep "wasm-bindgen =" Cargo.toml \ 141 | | cut -d '=' -f 2 \ 142 | | tr '"' ' ' \ 143 | | xargs 144 | } 145 | 146 | function header { 147 | echo 148 | echo '================================================================================' 149 | for x in "$@"; do 150 | echo "$x" 151 | done 152 | echo '--------------------------------------------------------------------------------' 153 | echo 154 | } 155 | 156 | function ensure_wasm_bindgen_installed { 157 | local version=$(get_wasm_bindgen_version) 158 | local version_string="wasm-bindgen $version" 159 | 160 | if test -x ./bin/wasm-bindgen; then 161 | if test "$(./bin/wasm-bindgen --version | xargs)" == "$version_string"; then 162 | echo 'Correct version of wasm-bindgen already installed locally.' 163 | return 164 | fi 165 | 166 | echo "Wrong version installed locally, updating to $version." 167 | else 168 | echo 'wasm-bindgen not installed locally, installing.' 169 | fi 170 | 171 | logged cargo \ 172 | cargo +nightly install -f wasm-bindgen-cli \ 173 | --version "$version" \ 174 | --root "$(pwd)" 175 | } 176 | 177 | function logged { 178 | local prefix="$1" 179 | shift 180 | echo "Running '$@'" 181 | "$@" > >(sed "s/^/$prefix: /") 2> >(sed "s/^/$prefix (stderr): /" >&2) 182 | echo 183 | } 184 | 185 | function ensure_template_filled_out { 186 | # If we are in the rustwasm/rust_wasm_template CI, then use `cargo-generate` 187 | # to fill in our own template variables. 188 | if grep -q '{{project-name}}' Cargo.toml; then 189 | test -x "$HOME/.cargo/bin/cargo-install-update" \ 190 | || logged cargo \ 191 | cargo install cargo-update 192 | test -x "$HOME/.cargo/bin/cargo-generate" || \ 193 | logged cargo \ 194 | cargo install cargo-generate 195 | logged "cargo install-update" \ 196 | cargo install-update cargo-generate 197 | 198 | rm -rf ./my_super_awesome 199 | logged "cargo generate" \ 200 | cargo-generate --git "$(pwd)" --name my_super_awesome 201 | cd ./my_super_awesome 202 | fi 203 | } 204 | 205 | main 206 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------