Commit Graph

22 Commits

Author SHA1 Message Date
Max Desiatov ae8015413b
Fix `carton dev` crashing with SO sanitizer (#239)
Previously, the file we need to include with the build to enable the stack overflow sanitizer was written as a temporary file. This didn't happen though on watcher rebuilds with `carton dev` and caused crashes when a code line containing `try!` relying on this file to be present was executed.

I think it's easier and more efficient to bundle this file in the `static.zip` file that already includes our JS entrypoints. We require `static.zip` to be downloaded and unpacked successfully into `~/.carton/static` before every build anyway. It makes more sense to sense the sanitizer file in `~/.carton/static/so_sanitizer.wasm` and use that instead writing and deleting it at a temporary path on every build.

I've also updated the JSKit dependency and cleaned up some linter warnings by moving large tuple values into a separate `BuildDescription` type.
2021-05-24 12:03:38 +01:00
Max Desiatov 116840c746
Fix browser testing for Safari, update tasks.json (#202)
* Fix browser testing for Safari, update tasks.json

* Remove autodiff code from `TestApp/main.swift`
2021-01-04 06:52:07 -05:00
Max Desiatov d42606d18f
Add more debug/release tasks to `tasks.json` 2020-12-19 15:19:12 +00:00
Max Desiatov 1c15282114
Bump JSKit, add support for testing in browsers (#173)
Resolves https://github.com/swiftwasm/carton/issues/42.

Also updates JavaScriptKit dependency to 0.9.0.

* Demangle and print Firefox stacktraces in terminal

* Update the entrypoints archive URL, rename file

* Add missing newline to `ProcessRunner.swift`

* Remove redundant `console.log` call from `dev.js`

* Detect destination env from `User-Agent` header

* Silence linter in tests where it can't be avoided

* Add support for basic testing in browsers

* Add a browser message on finish, shut down server

* Update JavaScriptKit to 0.9.0
2020-12-01 11:04:37 +00:00
Max Desiatov cbc04fb4f0
Build only test product and its deps for testing (#150)
Every Swift package with test targets has an implicit test product with `"\(package.name)PackageTests"` name. `swift build --build-tests` builds all products in a given package including the implicit test product. This doesn't work in situations where some of the products can't be compiled for Wasm, even when they are excluded with `condition: .when(platforms: [.macOS, .linux])` from test dependencies. This prevents tests from being built at all in such packages. OpenCombine is the primary victim of this problem.

Fortunately, the implicit test product can be accessed through the `--product` option passed to `swift build`. When using that option, only the test product and its dependencies are built. Products (and therefore their underlying targets) that aren't needed for tests are excluded from such builds. We should explicitly pass `--product` option to `swift build` instead of `--build-tests` in the `carton test` implementation to resolve the issue.

I've also added a new task to `tasks.json` that I previously used for testing `carton dev -v`.

`Dockerfile` has been updated to use the same toolchain as it does in `DefaultToolchain.swift`.

* Build only test product and its deps for testing

* Reuse product name interpolation

* Update `Dockerfile`
2020-11-02 13:52:33 +00:00
Max Desiatov 08956baf1d
Add separate Builder class, use WasmTransformer (#131)
Resolves #127.

* Add separate Builder class, use WasmTransformer

* Don't apply the transformer in non-browser environments

* Fix macOS Swift 5.2 build failure

* Fix Package.swift errors

* Fix cyclic dependency in `Package.swift`

* Bump WasmTransformer requirement to 0.0.1

* Rename `case wasmer` to `case other`
2020-10-21 08:48:03 +01:00
Max Desiatov a34ffd4249
Update `static.zip` URL and its hashes 2020-10-01 20:43:14 +01:00
Max Desiatov 6c1a12df6c
Bump version to 0.6.1, update `CHANGELOG.md` 2020-09-29 11:41:50 +01:00
Max Desiatov cd660a8d86
Use raw stdout if TerminalController is unavailable (#113)
TTY terminal output is unavailable on CI, or when users redirect output to a file or a pipe. In those cases `TerminalController` initializer returns `nil`. SwiftPM has a wrapper `InteractiveWriter` class for it, which writes output to stdout directly in that case. I've copied that, and replaced all uses of `TerminalController` with it. A VSCode task is added to test that.

In my testing it looks like download progress reporting is quite spammy, so it now has `removeDuplicates` Combine operator added to make it output only when values differ significantly from each other.

Additionally, SDK installs can hit GitHub API rate limit on CI nodes, so `carton` now reads `GITHUB_TOKEN` environment variable, which gives much higher limits to authenticated API users.

We can now also run various `carton` commands on CI for basic end-to-end testing.

Resolves #112.
2020-09-28 20:14:18 +01:00
Max Desiatov 53a1d46813
Implement `--custom-index-page` option (#101)
Allows passing a path to your custom `index.html` as `--custom-index-page` to `carton dev` and `carton bundle`. The entrypoint script is then injected into this file with a simple text substitution looking for a closing `</head>` tag. The assumption is that your custom `<body>` is not supposed to contain an unescaped `<head></head>`, and adding a dependency on a proper HTML parser to implement this injection is too costly.

Depends on #97.

Resolves #100.
2020-08-31 18:37:43 +01:00
Max Desiatov 5a5e7397eb
Implement `carton bundle` command (#97)
New `bundle.js` entrypoint is added, which only differs from `dev.js` in the lack of the WebSocket hot reloading bit.

`wabt` and `binaryen` Homebrew dependencies are added as required for `wasm-strip` and `wasm-opt` respectively that reduce the resulting bundle binary size.

All resulting bundle files except `index.html` are named by their content hashes to enable [cache busting](https://www.keycdn.com/support/what-is-cache-busting).

Resolves #16.
2020-08-31 16:29:47 +01:00
Max Desiatov db504a06c5
Fix watcher crashing in package subdirectories (#67)
Currently, when `carton dev` is launched in any subdirectory of the package not containing `Package.swift` it crashes. It's caused by `traverseRecursively` precondition failing when a non-directory (or non-existent) path is passed to it. I think `traverseRecursively` can handle non-existing paths well by returning an empty array, and the path itself when it's a file and not a directory. Thus the precondition check is not needed at all.

Non-existent paths were created due to a wrong assumption that the root package directory is always the current directory. This is now fixed by adding a new `inferManifestDirectory` function, which correctly calculates absolute paths of source directories before passing them to the watcher.

Additionally the watcher code in the `TSCBasic` code has its own precondition for non-empty path arrays passed to it. To avoid triggering it and staying extra-safe, we check for an empty watcher paths array and avoid watching anything at all.
2020-07-25 15:32:42 +01:00
Max Desiatov 9bfb3dde70
Add `list` flag and `testCases` argument to `test` (#52)
Refines the `carton test` command as a continuation of #42 work.
2020-07-15 19:12:28 +01:00
Max Desiatov b0cec40878
Add `carton sdk versions` to tasks.json 2020-07-07 15:52:07 +01:00
Max Desiatov a10028356c
Start implementing the `sdk` command 2020-06-23 21:39:48 +01:00
Max Desiatov b3b1144f59
Disable default subcommand, enable version flag 2020-06-22 13:11:20 +01:00
Max Desiatov 37e8d8145b
Pass --product, not --target to swift build 2020-06-16 20:53:58 +01:00
Max Desiatov 36b8c1d2a8
Refactor `dev` command, add tests to TestApp 2020-06-09 22:37:29 +01:00
Max Desiatov b8201ce478
Improve logging, add basic WebSocket handling 2020-06-07 19:25:08 +01:00
Max Desiatov 74d42393bb
Detect swift version, serve /main.wasm 2020-06-04 21:31:32 +01:00
Max Desiatov 00507280de
Add basic CLI commands 2020-05-04 22:31:53 +01:00
Max Desiatov e62d8aeda9
Add empty package with basic dependencies 2020-05-04 18:00:18 +01:00