Skip to content

Commit

Permalink
Add emscripten support
Browse files Browse the repository at this point in the history
  • Loading branch information
ASVIEST committed Jul 21, 2023
1 parent 29d15a6 commit cbf3e7f
Show file tree
Hide file tree
Showing 7 changed files with 1,960 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
[submodule "generator/third_party/dawn"]
path = generator/third_party/dawn
url = https://dawn.googlesource.com/dawn
[submodule "generator/third_party/emscripten"]
path = generator/third_party/emscripten
url = https://github.com/emscripten-core/emscripten
10 changes: 10 additions & 0 deletions generator/cli.nim
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import common
import gen_wgpu
import gen_dawn
import gen_emscripten

import std/os
import pkg/cligen

type Bindings {.pure.} = enum
`wgpu-native`
dawn
emscripten

func generatedFolder(b: Bindings): string=
case b:
of dawn:
"dawn"
of `wgpu-native`:
"wgpu_native"
of emscripten:
"emscripten"

proc cli(bindings: Bindings, release: bool = false, `out`: string)=
const thirdPartyDir = currentSourcePath.parentDir/"third_party"
Expand All @@ -37,5 +41,11 @@ proc cli(bindings: Bindings, release: bool = false, `out`: string)=
settings: settings,
wgpuDir: thirdPartyDir/"wgpu-native"
).generate(`out`)

of emscripten:
EmscriptenGenerator(
settings: settings,
emscriptenDir: thirdPartyDir/"emscripten"
).generate(`out`)

dispatch cli
28 changes: 28 additions & 0 deletions generator/gen_emscripten.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import common, helpers

import pkg/oolib
import std/[options, os]

class pub EmscriptenGenerator:
var
settings*: GeneratorSettings
emscriptenDir*: string

webgpuHeader: string

func preproc =
self.webgpuHeader = preprocWebgpuHeader(
self.webgpuHeader,
"", "importc"
)

proc generate: GeneratedFile =
self.webgpuHeader = readFile(
self.emscriptenDir/"system/include/webgpu/webgpu.h"
)
self.preproc()

("webgpu.nim", c2nim(self.webgpuHeader).get)

iterator virtualFS*(): GeneratedFile=
yield self.generate()
1 change: 1 addition & 0 deletions generator/third_party/emscripten
Submodule emscripten added at 87b495
3 changes: 2 additions & 1 deletion nimgpu.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ macro generateTask(name: untyped{ident}, bindings: static string): untyped=
taskRequires `nameStr`, "https://github.com/ASVIEST/c2nim#fix-clib"

generateTask(generate_wgpu, "wgpu-native")
generateTask(generate_dawn, "dawn")
generateTask(generate_dawn, "dawn")
generateTask(generate_emscripten, "emscripten")
2 changes: 2 additions & 0 deletions src/nimgpu/emscripten.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import emscripten/webgpu
export webgpu
Loading

0 comments on commit cbf3e7f

Please sign in to comment.