GeezerVison is showing github.com — added embedded example and conditional package flags · rarestype/JavaScriptKit@26b7a8e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -swift build --swift-sdk DEVELOPMENT-SNAPSHOT-2024-07-09-a-wasm32-unknown-wasi -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export=__main_argc_argv |
| 1 | +swift build --swift-sdk DEVELOPMENT-SNAPSHOT-2024-09-20-a-wasm32-unknown-wasi -Xswiftc -Xclang-linker -Xswiftc -mexec-model=reactor -Xlinker --export=__main_argc_argv |
Collapse file
Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +.DS_Store |
| 2 | +/.build |
| 3 | +/Packages |
| 4 | +/*.xcodeproj |
| 5 | +xcuserdata/ |
| 6 | +Package.resolved |
Collapse file
Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// swift-tools-version:5.10 |
| 2 | + |
| 3 | +import PackageDescription |
| 4 | + |
| 5 | +let package = Package( |
| 6 | + name: "Embedded", |
| 7 | + dependencies: [ |
| 8 | + .package(name: "JavaScriptKit", path: "../../"), |
| 9 | + .package(url: "https://github.com/swifweb/EmbeddedFoundation", branch: "0.1.0") |
| 10 | + ], |
| 11 | + targets: [ |
| 12 | + .executableTarget( |
| 13 | + name: "EmbeddedApp", |
| 14 | + dependencies: [ |
| 15 | + "JavaScriptKit", |
| 16 | + .product(name: "Foundation", package: "EmbeddedFoundation") |
| 17 | + ] |
| 18 | + ) |
| 19 | + ] |
| 20 | +) |
Collapse file
Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +# Embedded example |
| 2 | + |
| 3 | +```sh |
| 4 | +$ ./build.sh |
| 5 | +$ npx serve |
| 6 | +``` |
Collapse file
Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import JavaScriptKit |
| 2 | + |
| 3 | +// NOTE: it seems the embedded tree shaker gets rid of these exports if they are not used somewhere |
| 4 | +func _i_need_to_be_here_for_wasm_exports_to_work() { |
| 5 | + _ = _library_features |
| 6 | + _ = _call_host_function_impl |
| 7 | + _ = _free_host_function_impl |
| 8 | +} |
| 9 | + |
| 10 | +// TODO: why do I need this? and surely this is not ideal... figure this out, or at least have this come from a C lib |
| 11 | +@_cdecl("strlen") |
| 12 | +func strlen(_ s: UnsafePointer<Int8>) -> Int { |
| 13 | + var p = s |
| 14 | + while p.pointee != 0 { |
| 15 | + p += 1 |
| 16 | + } |
| 17 | + return p - s |
| 18 | +} |
Collapse file
Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import JavaScriptKit |
| 2 | + |
| 3 | +let alert = JSObject.global.alert.function! |
| 4 | +let document = JSObject.global.document |
| 5 | + |
| 6 | +print("Document title: \(document.title.string ?? "")") |
| 7 | + |
| 8 | +var divElement = document.createElement("div") |
| 9 | +divElement.innerText = "Hello, world 2" |
| 10 | +_ = document.body.appendChild(divElement) |
| 11 | + |
| 12 | +var buttonElement = document.createElement("button") |
| 13 | +buttonElement.innerText = "Alert demo" |
| 14 | +buttonElement.onclick = JSValue.object(JSClosure { _ in |
| 15 | + divElement.innerText = "Hello, world 3" |
| 16 | + return .undefined |
| 17 | +}) |
| 18 | + |
| 19 | +_ = document.body.appendChild(buttonElement) |
| 20 | + |
| 21 | +func print(_ message: String) { |
| 22 | + _ = JSObject.global.console.log(message) |
| 23 | +} |
Collapse file
Copy file name to clipboardExpand all lines: Examples/Embedded/_Runtime/_bundling_does_not_work_with_embedded