Skip to content

Commit

Permalink
feat: wasm language server and simplified build system (#1453)
Browse files Browse the repository at this point in the history
<img src="https://user-images.githubusercontent.com/1237390/216994444-73b32bd8-6495-4994-9f08-cb4dc3922be5.png" width="600" />

The Wing cli now has a `lsp` command which starts the language server. With this change, there are no more native parts of our toolchain. There are several ramifications for this:
- Nx no longer has to worry about `native` vs `wasm`, everything is just `build`
- The github workflow similarly only has one build job now where it builds everything
- The existing wing-language-server project has been removed, most of the code migrated to wingc under the wls module
- vscode now just uses npx to resolve the wing cli for the language server, alternatively an env var.

In the process of the simplification, Fixed #1396 by removing the npm registry stuff from hangar.
Also Fixes #821 because I removed the rust tests from tree-sitter-wing so we actually run all the tests.

**With all these changes, the build time is cut in half!**

### Future Improvement
Testing the rust crates still requires native builds. To make it faster, it only does a debug build. I attempted to use a wasmtime to instead run the tests through that, but ran into too many hurdles so decided to leave it.

### Intentional regression
Removed yarn from hangar. Had issues forcing it to resolve the SDK tarball. This worked before because mocking the registry is pretty brute force. This is specifically a problem with hangar, not the usage of wing with yarn. In order for it to work, we have to hack around yarn to force certain resolutions. At that point, what's the value in testing with it?

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
  • Loading branch information
MarkMcCulloh authored Feb 6, 2023
1 parent 9ac8132 commit d3efd2f
Show file tree
Hide file tree
Showing 50 changed files with 6,141 additions and 18,596 deletions.
155 changes: 16 additions & 139 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,19 @@ jobs:
- name: Setup Cargo Cache
uses: Swatinem/rust-cache@v2

- name: Install wasi-sdk
run: scripts/setup_wasi.sh

- name: Install Dependencies
uses: bahmutov/npm-install@v1

- name: Lint Nx
run: npx nx workspace-lint

- name: Build
- name: Build and Unit Test
uses: MansaGroup/nrwl-nx-action@v2
with:
targets: "build"
all: true
# Exclude native-dependent projects
args: "--exclude=wing-language-server,vscode-wing --configuration=release --output-style=stream --verbose"

- name: Test
uses: MansaGroup/nrwl-nx-action@v2
with:
targets: "test"
all: true
# Exclude E2E testing and native-dependent projects
args: "--exclude=hangar,wing-language-server,vscode-wing --configuration=release --output-style=stream --verbose"
# Exclude E2E testing
args: "--exclude=hangar --configuration=release --output-style=stream --verbose"

- name: Create NPM packages
uses: MansaGroup/nrwl-nx-action@v2
Expand All @@ -159,12 +148,18 @@ jobs:
name: wingsdk
path: libs/wingsdk/*.tgz

- name: Upload WingC Binary
- name: Upload WingC WASM
uses: actions/upload-artifact@v2
with:
name: wingc
path: target/wasm32-wasi/release/wingc.wasm

- name: Upload extension
uses: actions/upload-artifact@v2
with:
name: vscode-wing
path: apps/vscode-wing/vscode-wing.vsix

- name: "Publish Wing Playground"
if: github.event_name == 'push' && github.repository == 'winglang/wing'
uses: amondnet/vercel-action@v25.1.0
Expand All @@ -177,85 +172,21 @@ jobs:
github-comment: false
vercel-args: "--prod "

build-native:
needs: prepare
env:
PROJEN_BUMP_VERSION: ${{ needs.prepare.outputs.version }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
arch: x64
- os: ubuntu-latest
arch: x64
# TODO libnode build currently invalid for the following configs
# - os: macos-latest
# arch: arm64
# - os: ubuntu-latest
# arch: x86
runs-on: ${{ matrix.os }}
name: "Native Build"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODEJS_VERSION }}

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt
override: true

- name: Setup Cargo Cache
uses: Swatinem/rust-cache@v2

- name: Install Dependencies
uses: bahmutov/npm-install@v1
with:
# Don't need to install sub-project dependencies
install-command: npm install --ignore-scripts

- name: Lint Nx
run: npx nx workspace-lint

- name: Build
uses: MansaGroup/nrwl-nx-action@v2
with:
targets: "build-native"
projects: "wing-language-server"
args: "--configuration=release --output-style=stream --verbose"

- name: Test
uses: MansaGroup/nrwl-nx-action@v2
with:
targets: "test"
projects: "wingii"
args: "--configuration=release --output-style=stream --verbose"

- name: Upload Wing Language Server
uses: actions/upload-artifact@v2
with:
name: wing-language-server-${{ matrix.os }}-${{ matrix.arch }}
path: target/release/wing-language-server

e2e:
name: "E2E Testing"
needs:
- build-wasm
- prepare
strategy:
fail-fast: true
matrix:
runner:
- ubuntu-latest
# - macos-latest
node: [18, 19]
runs-on: ${{ matrix.runner }}
env:
HANGAR_WING_TGZ: ${{ github.workspace }}/wing/winglang-${{ needs.prepare.outputs.version }}.tgz
HANGAR_WINGSDK_TGZ: ${{ github.workspace }}/wingsdk/winglang-sdk-${{ needs.prepare.outputs.version }}.tgz
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -275,66 +206,12 @@ jobs:
install-command: npm ci --ignore-scripts

- name: Run E2E Tests
env:
# publishes to a dummy NPM registry, requires a non-empty token
NPM_TOKEN: "dummy-token"
run: |
export HANGAR_WING_TGZ="$(pwd)/$(find wing/*.tgz)"
export HANGAR_WINGSDK_TGZ="$(pwd)/$(find wingsdk/*.tgz)"
cd tools/hangar
HANGAR_WING_TGZ=$HANGAR_WING_TGZ HANGAR_WINGSDK_TGZ=$HANGAR_WINGSDK_TGZ npm run test
build-vscode:
name: "Build VSCode Extension"
needs:
- prepare
- build-native
- build-wasm
env:
PROJEN_BUMP_VERSION: ${{ needs.prepare.outputs.version }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download Build Artifacts
uses: actions/download-artifact@v2

- name: Prepare language server binaries
run: cp -r wing-language-server-* ./apps/vscode-wing/resources

- name: Prepare WingSDK files
run: |
mkdir -p apps/vscode-wing/resources/wingsdk
tar -xzf wingsdk/*.tgz -C apps/vscode-wing/resources/wingsdk --strip-components=1 package/package.json package/.jsii
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODEJS_VERSION }}

- name: Install Dependencies
uses: bahmutov/npm-install@v1

- name: Build
uses: MansaGroup/nrwl-nx-action@v2
with:
# build-multi assumes all required resources are present
targets: "build-multi"
projects: "vscode-wing"
args: "--configuration=release --output-style=stream --verbose"

- name: Upload extension
uses: actions/upload-artifact@v2
with:
name: vscode-wing
path: apps/vscode-wing/vscode-wing.vsix
working-directory: tools/hangar
run: npm run test

build:
needs:
- build-native
- build-wasm
- build-vscode
- e2e
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"type": "extensionHost",
"request": "launch",
"outFiles": ["${workspaceFolder}/apps/vscode-wing/lib/**/*.js"],
"env": {
"WING_BIN": "${workspaceFolder}/apps/wing/bin/wing",
},
"args": [
"--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-wing"
]
Expand Down
Loading

0 comments on commit d3efd2f

Please sign in to comment.