diff --git a/.gitignore b/.gitignore index 77dc09e..ddeef6b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ deps.zig gyro.lock */zig-cache dev.sh -test.js \ No newline at end of file +test.js +build \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..77dc09e --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +zig-out +zig-cache +.vscode +.zigmod +deps.zig +.gyro +gyro.lock +*/zig-cache +dev.sh +test.js \ No newline at end of file diff --git a/README.md b/README.md index 06f0dfe..37eb6fe 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ git submodule update --init --recursive # Build zig build -Drelease-fast +# Move to build/ folder. Your binary name will differ based on OS/CPU. +mkdir build && mv zig-out/bin/bunview-x86_64-linux ./build/bunview-x86_64-linux + # Run example (must have Bun installed) bun examples/main.js ``` \ No newline at end of file diff --git a/build.zig b/build.zig index ea8b0a9..c7947cc 100644 --- a/build.zig +++ b/build.zig @@ -3,7 +3,16 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { const target = b.standardTargetOptions(.{}); const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("bunview", "src/main.zig"); + const os = target.getOs().tag; + const arch = target.getCpuArch(); + + var name: []const u8 = undefined; + if(os == .linux and arch == .x86_64) { name = "bunview-x86_64-linux"; } + else if(os == .linux and arch == .aarch64) { name = "bunview-aarch64-linux"; } + else if(os == .macos and arch == .x86_64) { name = "bunview-x86_64-macos"; } + else if(os == .macos and arch == .aarch64) { name = "bunview-aarch64-macos"; } + + const exe = b.addExecutable(name, "src/main.zig"); // Link libc and libc++ //exe.linkLibC(); diff --git a/lib/index.js b/lib/index.js index 73e6440..9eaa4b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,7 +6,7 @@ import EventEmitter from 'events'; import { spawn } from "bun"; // Toggle debug logging -const DEBUG = true; +const DEBUG = false; export const SizeHint = { // Width and height are default size @@ -19,8 +19,17 @@ export const SizeHint = { FIXED: 3, }; +var TARGET_TRIPLE; +switch(process.arch + "-" + process.platform) { + case 'x64-linux': { TARGET_TRIPLE = "x86_64-linux"; break; } + case 'arm64-linux': { TARGET_TRIPLE = "aarch64-linux"; break; } + case 'x64-darwin': { TARGET_TRIPLE = "x86_64-macos"; break; } + case 'arm64-darwin': { TARGET_TRIPLE = "aarch64-macos"; break; } + default: throw new Error("Unsupported CPU/OS"); +} + // Path to bunview server -const EXE_PATH = __dirname + '/../zig-out/bin/bunview'; +const EXE_PATH = __dirname + `/../build/bunview-${TARGET_TRIPLE}`; /** * Window Class diff --git a/package.json b/package.json new file mode 100644 index 0000000..8e86212 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "bunview", + "version": "0.0.2", + "description": "Complete webview bindings for Bun", + "main": "lib/index.js", + "directories": { + "example": "examples", + "lib": "lib" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/theseyan/bunview.git" + }, + "files": [ + "build", + "lib" + ], + "keywords": [ + "webview", + "bun", + "gui", + "desktop-application" + ], + "author": "Sayan J. Das", + "license": "MIT", + "bugs": { + "url": "https://github.com/theseyan/bunview/issues" + }, + "homepage": "https://github.com/theseyan/bunview#readme" +}