Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for creating wasm builds #32

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ gopherjs-tool.exe
gopherjs-tool
skycoin.js
skycoin.js.map
test.wasm

# dependencies
/node_modules
/js/node_modules
/js/package-lock.json

# temp files
/coverage
/coverage
/js/coverage
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go:
install:
- if [[ ! -d $GOPATH/src/github.com/skycoin/skycoin-lite ]]; then mkdir -p $GOPATH/src/github.com/skycoin; ln -s $TRAVIS_BUILD_DIR $GOPATH/src/github.com/skycoin/skycoin-lite; fi
- cd $GOPATH/src/github.com/skycoin/skycoin-lite
- go get -t ./...
- GOOS=js GOARCH=wasm go get -t ./...
- go get -u github.com/FiloSottile/vendorcheck
# Install pinned golangci-lint, overriding the latest version install by make install-linters
- VERSION=1.17.1 ./ci-scripts/install-golangci-lint.sh
Expand All @@ -17,8 +17,8 @@ install:
script:
- cd $GOPATH/src/github.com/skycoin/skycoin-lite
- make check
- make build-js-min
- make test-suite-ts
- make build-wasm
- make test-suite-ts-wasm

notifications:
email:
Expand Down
67 changes: 27 additions & 40 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
# go-tests = true
# unused-packages = true

required = ["github.com/gopherjs/gopherjs"]
required = ["github.com/gopherjs/gopherjs", "github.com/stretchr/testify/require"]

[[constraint]]
branch = "develop"
name = "github.com/skycoin/skycoin"

[[constraint]]
name = "github.com/stretchr/testify"
revision = "2aa2c176b9dab406a6970f6a55f513e8a8c8b18f"

[prune]
go-tests = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this defaults to true, you may want to be explicit go-tests = false and leave a comment why (for the wasm tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding go-tests = false makes dep ensure say root prune options must be omitted instead of being set to false

unused-packages = true
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,37 @@ build-js-min: ## Build /skycoin/skycoin.go. The result is minified and saved in
go build -o gopherjs-tool vendor/github.com/gopherjs/gopherjs/tool.go
GOOS=linux ./gopherjs-tool build skycoin/skycoin.go -m -o js/skycoin.js

build-wasm: ## Build /wasm/skycoin.go. The result is saved in the repo root as skycoin-lite.wasm
GOOS=js GOARCH=wasm go build -o js/skycoin-lite.wasm ./wasm/skycoin.go

test-js: ## Run the Go tests using JavaScript
go build -o gopherjs-tool vendor/github.com/gopherjs/gopherjs/tool.go
./gopherjs-tool test ./skycoin/ -v

test-suite-ts: ## Run the ts version of the cipher test suite. Use a small number of test cases
test-suite-ts: ## Run the ts version of the cipher test suite for GopherJS. Use a small number of test cases
cd js && npm run test

test-suite-ts-extensive: ## Run the ts version of the cipher test suite. All the test cases
test-suite-ts-extensive: ## Run the ts version of the cipher test suite for GopherJS. All the test cases
cd js && npm run test-extensive

test-suite-ts-wasm: ## Run the ts version of the cipher test suite for wasm and additional tests
cd vendor/github.com/skycoin/skycoin/src/cipher && GOOS=js GOARCH=wasm go test -c -o test.wasm
cd vendor/github.com/skycoin/skycoin/src/cipher/secp256k1-go && GOOS=js GOARCH=wasm go test -c -o test.wasm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run these tests for cipher/ as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, no problem. Done in the lastest commit

cd vendor/github.com/skycoin/skycoin/src/cipher/secp256k1-go/secp256k1-go2 && GOOS=js GOARCH=wasm go test -c -o test.wasm
cd js && npm run test-wasm
cd js/tests && node cipher-wasm-internal.js
cd vendor/github.com/skycoin/skycoin/src/cipher && rm test.wasm
cd vendor/github.com/skycoin/skycoin/src/cipher/secp256k1-go && rm test.wasm
cd vendor/github.com/skycoin/skycoin/src/cipher/secp256k1-go/secp256k1-go2 && rm test.wasm

test:
go test ./... -timeout=10m -cover

lint: ## Run linters. Use make install-linters first.
vendorcheck ./...
golangci-lint run -c ./.golangci.yml ./...
GOOS=js GOARCH=wasm golangci-lint run -c ./.golangci.yml ./...
@# The govet version in golangci-lint is out of date and has spurious warnings, run it separately
go vet -all ./...
GOOS=js GOARCH=wasm go vet -all ./...

check: lint test ## Run tests and linters

Expand Down
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# Skycoin Liteclient

This repository contains a small wrapper for Skycoin (written in Go) to provide mobile and JS bindings.
This repository contains a small wrapper for Skycoin (written in Go) to provide mobile, JS and wasm bindings.

At the moment it is used to compile
an [Android Archive](https://developer.android.com/studio/projects/android-library.html), an iOS Framework,
and a JS library with [gopherjs](https://github.com/gopherjs/gopherjs).
a (deprecated) JS library with [gopherjs](https://github.com/gopherjs/gopherjs) and a wasm file.

Supports go1.10+.
Supports go1.10+. However, for compiling the wasm file you must use Go v1.12.x (compatibility
with Go v1.13+ is not guaranteed).

## Important note about error handling

Expand All @@ -31,15 +32,26 @@ $ gomobile bind -target=ios github.com/skycoin/skycoin-lite/mobile

## Compile javascript library

> IMPORTANT: the ability for transpiling the code to a JavaScript library is deprecated due to important
performance issues and should not be used. Please compile to a wasm file instead.

For the compilation process to javascript library, we use [gopherjs](https://github.com/gopherjs/gopherjs).

To compile the library use `make build-js` or `make build-js-min` (if you want the final file to be minified).
After compiling, the main.js and main.js.map files will be created/updated in the root of the repository.
After compiling, the `skycoin.js` and `skycoin.js.map` files will be created/updated in the `js` folder.

## Compile wasm file

> IMPORTANT: you need Go v1.12.x to use this function. It is not guaranteed to work with Go v1.13+.

To compile the wasm file use `make build-wasm`. After compiling, the `skycoin-lite.wasm` file will be
created/updated in the `js` folder.

## Development

The javascript library is created starting from [gopher/main.go](gopher/main.go). The Android/iOS library is
created starting from [mobile/api.go](mobile/api.go).
The javascript library is created starting from [skycoin/skycoin.go](skycoin/skycoin.go). The wasm file is
created starting from [wasm/skycoin.go](wasm/skycoin.go). The Android/iOS library is created starting
from [mobile/api.go](mobile/api.go).

### Running tests

Expand All @@ -66,22 +78,37 @@ npm install --global source-map-support

and make sure `NODE_PATH` is set to the value of `npm root --global` in your environment.

#### TS cipher test suite
#### TS cipher test suite for GopherJS

> IMPORTANT: the ability for transpiling the code to a JavaScript library is deprecated due to important
performance issues and should not be used. Please compile to a wasm file instead.

The repository includes a TypeScript version of the cipher test suite, originally written in Go in
the Skycoin main repository. Because the tests take a significant amount of time to complete in
JavaScript/TypeScript, the test suite can be run with a limited number of cases with
the Skycoin main repository. It test the GopherJS version of the library, so before
using it you must compile the GopherJS version with `make build-js` or `make build-js-min`.
Because testing the GopherJS version takes a significant amount of time to complete, the test suite
can be run with a limited number of cases with:

```sh
make test-suite-ts
```

The test suite can be run with all test cases using
The test suite can be run with all test cases using:

```sh
make test-suite-ts-extensive
```

#### TS cipher test suite for wasm

There is test suite for the wasm version of the library, just like there is one for the GopherJS
version. Before using it you must compile the wasm version with `make build-wasm`. The test suite
can be run with:

```sh
make test-suite-ts-wasm
```

### Formatting

All `.go` source files should be formatted `goimports`. You can do this with:
Expand Down
4 changes: 2 additions & 2 deletions js/karma.conf.js → js/karma-gopher.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module.exports = function (config) {
require('karma-typescript')
],
files: [
'tests/*.spec.ts',
'tests/cipher.spec.ts',
{ pattern: 'tests/test-fixtures/*.golden', included: false },
{ pattern: 'tests/*.ts', included: true },
{ pattern: 'tests/utils.ts', included: true },
{ pattern: 'skycoin.js', included: true }
],
preprocessors: {
Expand Down
Loading