Skip to content

Commit

Permalink
iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
elringus committed Sep 5, 2023
1 parent 12c5791 commit 3b53cd6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DotNet/Bootsharp/Bootsharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyTitle>Bootsharp</AssemblyTitle>
<Title>Bootsharp</Title>
<PackageId>Bootsharp</PackageId>
<Version>0.0.2-alpha.6</Version>
<Version>0.0.2-alpha.28</Version>
<Authors>Elringus</Authors>
<Description>Compile C# solution into single-file ES module with auto-generated JavaScript bindings and type definitions.</Description>
<PackageTags>javascript typescript ts js wasm bindings interop codegen</PackageTags>
Expand Down
15 changes: 15 additions & 0 deletions DotNet/Bootsharp/Build/Bootsharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<BootsharpPackageDirectory Condition="'$(BootsharpPackageDirectory)' == 'default'">$(BootsharpPublishDirectory)</BootsharpPackageDirectory>
</PropertyGroup>

<!-- https://github.com/dotnet/runtime/issues/91558 -->
<PropertyGroup>
<BootsharpDotNetMain>$(BootsharpBuildDirectory)/dotnet.js</BootsharpDotNetMain>
<BootsharpDotNetNative>$(BootsharpBuildDirectory)/dotnet.native.js</BootsharpDotNetNative>
</PropertyGroup>
<WriteLinesToFile File="$(BootsharpDotNetMain)"
Lines="$([System.IO.File]::ReadAllText($(BootsharpDotNetMain)).Replace('=import.meta.url','=&quot;file:/&quot;'))"
Overwrite="true"/>
<WriteLinesToFile File="$(BootsharpDotNetNative)"
Lines="$([System.IO.File]::ReadAllText($(BootsharpDotNetNative)).Replace('var _scriptDir = import.meta.url','var _scriptDir = &quot;file:/&quot;'))"
Overwrite="true"/>
<WriteLinesToFile File="$(BootsharpDotNetNative)"
Lines="$([System.IO.File]::ReadAllText($(BootsharpDotNetNative)).Replace('new URL('dotnet.native.wasm', import.meta.url).href','&quot;file:/&quot;'))"
Overwrite="true"/>

<!-- Generate bindings, types and (optionally) embed binaries. -->
<BuildBootsharp BuildDirectory="$(BootsharpBuildDirectory)"
InspectedDirectory="$(BootsharpInspectedDirectory)"
Expand Down
2 changes: 1 addition & 1 deletion JavaScript/src/bootsharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { resources } from "./resources";
import { builder, runtime, native } from "./external";

export default { boot, exit, resources, dotnet: { builder, runtime, native } };
// @ts-ignore (resolved when building C# solution)
// @ts-expect-error (resolved when building C# solution)
export * from "./bindings.g";
5 changes: 2 additions & 3 deletions JavaScript/src/external.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// @ts-ignore (resolved when building C# solution)
// @ts-expect-error (resolved when building C# solution)
import * as runtimeModule from "./dotnet.runtime";
// @ts-ignore (resolved when building C# solution)
// @ts-expect-error (resolved when building C# solution)
import * as nativeModule from "./dotnet.native";
// @ts-ignore (resolved when building C# solution)
import * as dotnetModule from "./dotnet";
import type { DotnetHostBuilder, MonoConfig, AssetEntry, ModuleAPI } from "./dotnet.d.ts";

Expand Down
2 changes: 1 addition & 1 deletion JavaScript/src/imports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore (resolved when building C# solution)
// @ts-expect-error (resolved when building C# solution)
import * as bindings from "./bindings.g";
import type { RuntimeAPI } from "./dotnet.d.ts";
import type { Event } from "./event";
Expand Down
13 changes: 11 additions & 2 deletions JavaScript/src/resources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-ignore (resolved when building C# solution)
// @ts-expect-error (resolved when building C# solution)
import generated from "./resources.g";
import { RuntimeConfig, AssetEntry, runtime, native } from "./external";

Expand Down Expand Up @@ -69,5 +69,14 @@ function toBinary(data: Uint8Array | string): Uint8Array {
if (typeof data !== "string") return data;
if (typeof window === "object") return Uint8Array.from(window.atob(data), c => c.charCodeAt(0));
if (typeof Buffer === "function") return Buffer.from(data, "base64");
throw Error("Failed to convert base64 to binary: unknown environment.");

const abc = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"];
let result = [];
for (let i = 0; i < data.length / 4; i++) {
let chunk = [...data.slice(4 * i, 4 * i + 4)];
let bin = chunk.map(x => abc.indexOf(x).toString(2).padStart(6, "0")).join("");
let bytes = bin.match(/.{1,8}/g)?.map(x => +("0b" + x)) ?? [];
result.push(...bytes.slice(0, 3 - Number(data[4 * i + 2] == "=") - Number(data[4 * i + 3] == "=")));
}
return Uint8Array.from(result);
}
Binary file modified Samples/Code/bootsharp-0.0.2.vsix
Binary file not shown.
2 changes: 1 addition & 1 deletion Samples/Code/src/extension.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import bootsharp, { Backend, Frontend } from "../../Minimal/cs/bin/bootsharp/bootsharp";
import bootsharp, { Backend, Frontend } from "../../Minimal/cs/bin/bootsharp/bootsharp.js";

export async function activate(context) {
Frontend.getName = () => "VS Code";
Expand Down

0 comments on commit 3b53cd6

Please sign in to comment.