Skip to content

Commit

Permalink
feat: Added support for wasm32-unknown-unknown target
Browse files Browse the repository at this point in the history
  • Loading branch information
OtaK committed Jun 16, 2022
1 parent bdd0fce commit 75a91f2
Show file tree
Hide file tree
Showing 86 changed files with 7,189 additions and 3,095 deletions.
14 changes: 5 additions & 9 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[env]
EMCC_CFLAGS = "-O3"
CC_armv7-linux-androideabi = "armv7a-linux-androideabi30-clang"
CXX_armv7-linux-androideabi = "armv7a-linux-androideabi30-clang++"
AR_armv7-linux-androideabi = "llvm-ar"
Expand All @@ -13,14 +12,11 @@ CC_i686-linux-android = "i686-linux-android30-clang"
CXX_i686-linux-android = "i686-linux-android30-clang++"
AR_i686-linux-android = "llvm-ar"

[target.wasm32-unknown-emscripten]
rustflags = [
"-C", "link-args=./support/wasm/gxx_personality_v0_stub.o",
"-C", "link-args=--bind,--export-dynamic",
"-C", "target-feature=+crt-static",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Wl,--no-entry",
]
[unstable]
build-std = ["std", "panic_abort"]

[target.wasm32-unknown-unknown]
rustflags = "-Ctarget-feature=+atomics"

# Android linkage
[target.armv7-linux-androideabi]
Expand Down
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = space
indent_size = 4

[*.{md,mdx}]
trim_trailing_whitespace = false
4 changes: 1 addition & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
- name: Coverage
uses: actions-rs/[email protected]
with:
args: '--ignore-tests --run-types Tests --exclude-files "extras/*" --exclude-files "cli/*"'
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
fail_ci_if_error: true
18 changes: 18 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,41 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- uses: Swatinem/rust-cache@v1

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check

- name: Run build
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose

- name: Run build (wasm)
run: |
wasm-pack build --release keystore
wasm-pack build --release crypto
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose

- name: Run tests (wasm)
run: |
wasm-pack test --release --headless --chrome keystore
wasm-pack test --release --headless --chrome crypto
185 changes: 166 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
sample-projects/CoreCryptoTestApp/**/build/
sample-projects/CoreCryptoTestApp/app/src/main/jniLibs/**/*.so

crypto-ffi/bindings/swift/out
crypto-ffi/bindings/swift/.build
crypto-ffi/bindings/swift/.swiftpm

platforms/web/*

sample-projects/ios/.build
sample-projects/ios/.swiftpm
.DS_Store

# Test databases leftovers
*.edb
*.edb-salt
*.db

### Rust ###
Cargo.lock
# Generated by Cargo
# will have compiled files and executables
**/debug/
Expand All @@ -10,29 +29,157 @@
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Test databases leftovers
*.edb
*.edb-salt
*.db

# End of https://www.toptal.com/de§velopers/gitignore/api/rust

sample-projects/CoreCryptoTestApp/**/build/
sample-projects/CoreCryptoTestApp/app/src/main/jniLibs/**/*.so

crypto-ffi/bindings/swift/out
crypto-ffi/bindings/swift/.build
crypto-ffi/bindings/swift/.swiftpm

sample-projects/ios/.build
sample-projects/ios/.swiftpm
.DS_Store

Cargo.lock

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
out/

# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
package-lock.json
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

# End of https://www.toptal.com/developers/gitignore/api/node
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = ["crypto", "crypto-ffi", "keystore", "mls-provider", "cli"]
exclude = ["extras/anycrypto", "extras/core-ds"]
resolver = "2"

[patch.crates-io.proteus]
git = "https://github.com/wireapp/proteus"
Expand All @@ -9,9 +10,20 @@ branch = "otak/sodiumoxide-0.2.7"
[patch.crates-io.openmls]
git = "https://github.com/wireapp/openmls"
branch = "develop"
package = "openmls"

[patch.crates-io.openmls_rust_crypto]
git = "https://github.com/wireapp/openmls"
branch = "develop"
package = "openmls_rust_crypto"

[patch.crates-io.openmls_traits]
git = "https://github.com/wireapp/openmls"
branch = "develop"
package = "openmls_traits"

[profile.release]
lto = true
codegen-units = 1
opt-level = "s"
# panic = "abort"
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ No license is granted to the Wire trademark and its associated logos, all of whi

* CoreCrypto: Abstracts MLS & Proteus in a unified API
* CoreCryptoFFI: FFI bindings for iOS, Android and WASM
* Keystore: Encrypted Keystore powered by SQLCipher
* Keystore: Encrypted Keystore powered by SQLCipher on all platforms except WASM. WASM uses an IndexedDB-backed, encrypted store with AES256-GCM
* MlsProvider: RustCrypto + Keystore MLS provider

## Usage
Expand Down Expand Up @@ -68,6 +68,12 @@ Install linux targets
rustup target add x86_64-unknown-linux-gnu
```

### WASM

* Install [wasm-pack](https://rustwasm.github.io/wasm-pack/)
* Install the wasm32-unknown-unknown toolchain `rustup target add wasm32-unknown-unknown`
* Install node.js (recommended way is via [Volta](https://volta.sh/))

### Bindings

Build bindings for Android, JVM, iOS and WASM
Expand All @@ -85,7 +91,7 @@ cargo make "copy-android-resources"
cargo make "create-framework"
# builds wasm binary
cargo make "wasm-release"
cargo make wasm
```

## Publishing for Android / JVM
Expand All @@ -97,3 +103,7 @@ cd kotlin
./gradlew :jvm:publishToMavenLocal
./gradlew :android:publishToMavenLocal
```

## Publishing for JS / WASM

Given that you are logged in NPM and can publish to `@wireapp/core-crypto`, you can just `npm publish` to push a new version
Loading

0 comments on commit 75a91f2

Please sign in to comment.