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

Add README.md #1

Merged
merged 6 commits into from Mar 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 88 additions & 1 deletion README.md
@@ -1 +1,88 @@
# swift-for-wasm-examples
# Swift for WebAssembly Examples

A repository with a "Swift Audio Workstation" example built with Swift for WebAssembly running in the browser.

## Requirements

WebAssembly support in Swift is available for preview in latest Trunk Development (main) snapshots at [swift.org/download](https://www.swift.org/download).

### macOS

1. Make sure you have Xcode installed.
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
2. Verify selected Xcode path by running `xcode-select -p` in the terminal. If that's not the case, follow the steps provided in ["How do I select the default version of Xcode"](https://developer.apple.com/library/archive/technotes/tn2339/_index.html#//apple_ref/doc/uid/DTS40014588-CH1-HOW_DO_I_SELECT_THE_DEFAULT_VERSION_OF_XCODE_TO_USE_FOR_MY_COMMAND_LINE_TOOLS_) section of ["Building from the Command Line with Xcode FAQ"](https://developer.apple.com/library/archive/technotes/tn2339/_index.html).
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
3. Download latest development snapshot, for example [`DEVELOPMENT-SNAPSHOT-2024-03-07-a`](https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2024-03-07-a/swift-DEVELOPMENT-SNAPSHOT-2024-03-07-a-osx.pkg) or later.
4. Run the downloaded installer. Select "Install for me only" option during installation.
5. Select the newly installed snapshot in terminal:

```sh
export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw \
~/Library/Developer/Toolchains/swift-latest.xctoolchain/Info.plist)
```
6. Install `wasm-ld` linker with [Homebrew](https://brew.sh/):
```sh
brew install llvm
```

### Docker

1. Run this command in a clone of this repository:
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

```sh
docker run --rm -it -v $(pwd):/root/build swiftlang/swift:nightly-jammy /bin/bash
```

This will mount the clone directory as a volume in the Docker container and also make final build products available to your host system.
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

2. Navigate to the package directory within the container:

```sh
cd /root/build
```

## How to Build and Run

Assuming you have the latest development snapshots selected per the instructions above, build the package with this command:
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

```sh
swift build --triple wasm32-unknown-none-wasm -c release --product swift-audio
```

Start an HTTP server in the cloned directory of the package:
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

```sh
python3 -m http.server
```

Open http://localhost:8000 in your browser to see the project running.

## License

Copyright 2024 Apple Inc. and the Swift project authors. Licensed under Apache License v2.0 with Runtime Library Exception.

See [https://swift.org/LICENSE.txt](https://swift.org/LICENSE.txt) for license information.

See [https://swift.org/CONTRIBUTORS.txt](https://swift.org/CONTRIBUTORS.txt) for Swift project authors.

See [`LICENSE-vendored.md`](https://github.com/apple/swift-for-wasm-examples/blob/main/LICENSE-vendored.md) for exact licenses of code vendored in this repository. Specifically:

1. Code in `Sources/dlmalloc` directory is derived from wasi-libc: https://github.com/WebAssembly/wasi-libc
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

> wasi-libc as a whole is multi-licensed under the Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, and the MIT License. See the LICENSE-APACHE-LLVM, LICENSE-APACHE and LICENSE-MIT files, respectively, for details.
>
> Portions of this software are derived from third-party works covered by their own licenses:
>
> dlmalloc/ - CC0; see the notice in malloc.c for details emmalloc/ - MIT; see the notice in emmalloc.c for details libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details libc-top-half/musl/ - MIT; see the COPYRIGHT file for details
>
> wasi-libc's changes to these files are multi-licensed under the Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, the MIT License, and the original licenses of the third-party works.

2. .wav format encoding implementation is derived from WavAudioEncoder.js library https://github.com/higuma/wav-audio-encoder-js and is licensed as following:
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

> The MIT License (MIT)
>
> Copyright (c) 2015 Yuji Miyane

3. Code in `Sources/VultDSP` directory is derived from https://github.com/vult-dsp/vult and is licensed as following:
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved

> MIT License
>
> Copyright (c) 2017 Leonardo Laguna Ruiz