Skip to content

Commit 810c6ce

Browse files
authored
Convert to typescript (#77)
* Fix spelling of "formated" fixes shader-slang/slang#5714 * Initial work on typescript conversion * Revert "Initial work on typescript conversion" This reverts commit 2adca03. * initial work on typescript conversion * remove old files * fix types for dependencies * import across files and other fixes * Set up slang wasm types * Changes for working js code, at the cost of my sanity, a million type errors, and reflection not working * typing improvements and reflection fix * fix remaining element errors * Improve types * fix incorrect language setting * fix floating variable types + ui code improvements * build improvements * reenable deployment * update readme to be closer to version on main * fix order of typescript build * download artifact so it can be used for deploy
1 parent c5509f3 commit 810c6ce

24 files changed

+1132
-2270
lines changed

.github/workflows/jekyll-gh-pages.yml

+40-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ jobs:
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v4
32-
- name: Setup Pages
33-
uses: actions/configure-pages@v5
3432

3533
- name: get slang head commit
3634
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y ninja-build
3737
mkdir slang-repo
3838
pushd slang-repo
3939
git clone https://github.com/shader-slang/slang.git
@@ -55,6 +55,7 @@ jobs:
5555
path: |
5656
./slang-wasm.wasm.gz
5757
./slang-wasm.js
58+
./slang-wasm.d.ts
5859
key: ${{hashFiles('key.txt')}}
5960

6061
- name: restore spirv-tools
@@ -64,11 +65,14 @@ jobs:
6465
path: |
6566
./spirv-tools.wasm
6667
./spirv-tools.js
68+
./spirv-tools.d.ts
6769
key: ${{hashFiles('key-spirv-tool.txt')}}
6870

6971
- name: slang-wasm build
7072
if: steps.cache_slang.outputs.cache-hit != 'true'
7173
run: |
74+
sed -i -e 's/\r$//' ./slang-wasm-build.sh
75+
chmod +x ./slang-wasm-build.sh
7276
./slang-wasm-build.sh
7377
7478
- name: save slang-wasm
@@ -78,11 +82,14 @@ jobs:
7882
path: |
7983
./slang-wasm.wasm.gz
8084
./slang-wasm.js
85+
./slang-wasm.d.ts
8186
key: ${{hashFiles('key.txt')}}
8287

8388
- name: spirv-tools-wasm build
8489
if: steps.cache_spirv_tools.outputs.cache-hit != 'true'
8590
run: |
91+
sed -i -e 's/\r$//' ./spirv-tool-wasm-build.sh
92+
chmod +x ./spirv-tool-wasm-build.sh
8693
./spirv-tool-wasm-build.sh
8794
8895
- name: save spirv-tools-wasm
@@ -92,6 +99,7 @@ jobs:
9299
path: |
93100
./spirv-tools.wasm
94101
./spirv-tools.js
102+
./spirv-tools.d.ts
95103
key: ${{hashFiles('key-spirv-tool.txt')}}
96104

97105
- name: Cleanup workspace
@@ -100,13 +108,29 @@ jobs:
100108
rm -rf emsdk
101109
rm -rf spirv-tools
102110
111+
- name: Build typescript
112+
run: |
113+
npm install
114+
npx tsc
115+
103116
- name: Build with Jekyll
104117
uses: actions/jekyll-build-pages@v1
105118
with:
106119
source: ./
107120
destination: ./_site
108-
- name: Upload artifact
109-
uses: actions/upload-pages-artifact@v3
121+
122+
- name: Copy depencencies
123+
run: |
124+
sudo mkdir ./_site/node_modules
125+
sudo cp -r node_modules/jjsontree.js ./_site/node_modules/jjsontree.js
126+
sudo cp -r node_modules/requirejs ./_site/node_modules/requirejs
127+
sudo cp -r node_modules/pako ./_site/node_modules/pako
128+
- name: Upload export artifact
129+
uses: actions/upload-artifact@v4
130+
with:
131+
name: site-artifact
132+
path: ./_site/
133+
compression-level: 1
110134

111135
# Deployment job
112136
deploy:
@@ -116,6 +140,18 @@ jobs:
116140
runs-on: ubuntu-latest
117141
needs: build
118142
steps:
143+
- name: Setup Pages
144+
uses: actions/configure-pages@v5
145+
146+
- name: Download a single artifact
147+
uses: actions/download-artifact@v4
148+
with:
149+
name: site-artifact
150+
path: ./_site/
151+
152+
- name: Upload artifact
153+
uses: actions/upload-pages-artifact@v3
154+
119155
- name: Deploy to GitHub Pages
120156
id: deployment
121157
uses: actions/deploy-pages@v4

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
slang-wasm.js
2+
slang-wasm.d.ts
23
slang-wasm.wasm
34
slang-wasm.wasm.gz
5+
spirv-tools.js
6+
spirv-tools.d.ts
7+
spirv-tools.wasm
8+
node_modules/*
9+
package-lock.json
10+
*.js
11+
out/*

README.md

+21-68
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,26 @@ git clone https://github.com/shader-slang/slang-playground.git
1010

1111
### Prerequisites
1212

13-
Ensure the following tools are installed and properly configured on your system:
14-
- **CMake** (Version 3.25 or greater is preferred, if you're on a lower version please see [build with older cmake](https://github.com/shader-slang/slang/blob/master/docs/building.md#building-with-an-older-cmake))
15-
- A **C++ compiler** with C++17 support (GCC, Clang, or MSVC)
16-
- A **CMake-compatible build backend** (e.g., Ninja or Visual Studio)
17-
- **Python 3** (Required for building and running the server)
18-
- **gzip** (For compressing `.wasm` files)
19-
20-
To install the above tools on linux, run:
21-
```bash
22-
sudo apt update
23-
sudo apt install build-essential cmake ninja-build python3 python3-pip gzip
24-
```
25-
26-
We need to build `slang-wasm` because we need `slang-wasm.js` and `slang-wasm.wasm` files.
27-
The reason they're not included in this repo is that they are big binary files, and the result of building top of tree slang, so making this part of the CI build process makes the most sense.
28-
29-
### Building `slang-wasm`
30-
31-
1. Clone the [Slang repository](https://github.com/shader-slang/slang) and fetch its submodules:
32-
```bash
33-
git clone https://github.com/shader-slang/slang --recursive
13+
* Install [Docker](https://www.docker.com/get-started/)
14+
* Install [Github CLI](https://cli.github.com/)
15+
* install [Github Act](https://github.com/nektos/gh-act) as an extension using `gh extension install https://github.com/nektos/gh-act`
3416

35-
cd slang
36-
```
37-
38-
2. Follow the instructions in the [WebAssembly build section](https://github.com/shader-slang/slang/blob/master/docs/building.md#webassembly-build) of the Slang documentation to:
39-
- Set up the [Emscripten SDK](https://github.com/emscripten-core/emsdk) by installing and activating it.
40-
- Build the WebAssembly target (`slang-wasm.js` and `slang-wasm.wasm`) using the documented cross-compilation steps.
41-
42-
3. Once the build completes, locate `slang-wasm.js` and `slang-wasm.wasm` in the `build.em/Release/bin` directory
43-
44-
4. Copy `slang-wasm.js` and `slang-wasm.wasm` to the **root of the playground directory**.
45-
46-
5. Compress the `slang-wasm.wasm` file using gzip:
47-
```bash
48-
gzip -k slang-wasm.wasm
49-
```
17+
### Building
5018

51-
### Building `spirv-tool`
52-
53-
To enable SPIR-V disassembly in the playground (alongside the SPIR-V binary compilation supported by `slang-wasm.js`), you need to build the WebAssembly version of `spirv-tool`. This is necessary because `slang-wasm.js` does not include the SPIR-V disassembler.
54-
55-
1. Refer to the build process outlined in the CI configuration:
56-
- [GitHub Workflow](https://github.com/shader-slang/slang-playground/blob/main/.github/workflows/jekyll-gh-pages.yml#L43)
57-
- [Build Script](https://github.com/shader-slang/slang-playground/blob/main/spirv-tool-wasm-build.sh)
58-
59-
2. Use the provided [`spirv-tool-wasm-build.sh`](https://github.com/shader-slang/slang-playground/blob/main/spirv-tool-wasm-build.sh) script to compile the WebAssembly build of `spirv-tool`.
60-
61-
3. Once built, place the resulting files (`spirv-tools.wasm` and `spirv-tools.js`) in the **root of the playground directory** alongside `slang-wasm.js` and `slang-wasm.wasm`.
62-
63-
By completing this step, the playground will support SPIR-V disassembly features.
19+
* Run `gh act -P ubuntu-latest=catthehacker/ubuntu:full-latest -j 'build' --artifact-server-path ./out`
20+
* This will create a file at `out/1/artifact/artifact.zip`
21+
* Extracting the zip file will provide a directory from which you can host the website
6422

6523
### Starting the Server
6624

67-
1. Navigate to the root of your playground directory (where `slang-wasm.js` and `slang-wasm.wasm.gz` are located).
25+
1. Navigate to the root of your webfiles (where `slang-wasm.js` and `slang-wasm.wasm.gz` are located) either in the artifact folder or the root of your playground directory.
26+
6827
```bash
6928
cd slang-playground
7029
```
7130

7231
2. Start a Python web server to host the files:
32+
7333
```bash
7434
python -m http.server 8000
7535
```
@@ -78,26 +38,19 @@ By completing this step, the playground will support SPIR-V disassembly features
7838

7939
If any issues arise, ensure the `.wasm` file is properly compressed (`slang-wasm.wasm.gz`) and located in the correct directory.
8040

81-
This process of: build -> run, should work alone.
41+
## Iterate
8242

83-
## Iterating on Development Using build.mk
43+
In order to avoid the expensive build process, copy the following files from the output directory to the main directory:
8444

85-
Alternatively you can build using the `build.mk` file.
45+
* `slang-wasm.js`
46+
* `slang-wasm.d.ts`
47+
* `slang-wasm.wasm`
48+
* `slang-wasm.wasm.gz`
49+
* `spirv-tools.js`
50+
* `spirv-tools.d.ts`
8651

87-
Set up the environment as follows:
52+
Run `npm install` to install dependencies.
8853

89-
```bash
90-
## The output directory where to output target (non-source) files
91-
export TRY_SLANG_TARGET_DIRECTORY_PATH="path-to-slang-target-directory"
92-
## Path to the hello-emscripten source tree
93-
export TRY_SLANG_SOURCE_DIRECTORY_PATH="path-to-slang-source-directory"
94-
## Slang source directory
95-
export TRY_SLANG_SLANG_SOURCE_DIRECTORY_PATH="path-to-slang-directory"
96-
```
54+
You can then run `npx tsc` and host the webserver from the main directory. You will either need to run `npx tsc` whenever you make a code change, or you can run `npx tsc --watch` to continuously compile.
9755

98-
1. Make the necessary changes to your source code.
99-
2. Build the updated runtime by running:
100-
```bash
101-
make -f ./build.mk website_runtime
102-
```
103-
3. Refresh `http://localhost:8000` in your browser to view the changes.
56+
Now load or reload `localhost:8000` in your browser to see the results.

build.mk

-100
This file was deleted.

0 commit comments

Comments
 (0)