Skip to content

Commit

Permalink
WIP bindings
Browse files Browse the repository at this point in the history
Former-commit-id: 74e75d6
  • Loading branch information
Jarred-Sumner committed Jul 18, 2021
1 parent e2b9d4c commit 79cd2fb
Show file tree
Hide file tree
Showing 33 changed files with 1,986 additions and 291 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ esbuilddir
outdir/
outcss
.next
txt.js
txt.js
.idea
48 changes: 48 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"configurations": [
{
"name": "Mac",
"forcedInclude": [
"${workspaceFolder}/src/javascript/jsc/bindings/root.h"
],
"includePath": [
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders/",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/WTF/Headers/**",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/*",
"${workspaceFolder}/src/JavaScript/jsc/bindings/**",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/Source/bmalloc/**",
"${workspaceFolder}/src/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers/"
],
"browse": {
"path": [
"${workspaceFolder}/src/javascript/jsc/bindings/*",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders/",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/WTF/Headers/**",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/WebKitBuild/Release/*",
"${workspaceFolder}/src/JavaScript/jsc/bindings/**",
"${workspaceFolder}/src/JavaScript/jsc/WebKit/Source/bmalloc/**",
"${workspaceFolder}/src/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers/"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"defines": [
"STATICALLY_LINKED_WITH_JavaScriptCore=1",
"STATICALLY_LINKED_WITH_WTF=1",
"BUILDING_WITH_CMAKE=1",
"NOMINMAX",
"ENABLE_INSPECTOR_ALTERNATE_DISPATCHERS=0",
"BUILDING_JSCONLY__",
"USE_FOUNDATION=1"
],
"macFrameworkPath": [
// "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/local/opt/llvm/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
33 changes: 33 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"git.autoRepositoryDetection": "openEditors",
"search.quickOpen.includeSymbols": true,
"search.seedWithNearestWord": true,
"search.smartCase": true,
"search.exclude": {
"src/javascript/jsc/WebKit/**/*": true
},
"search.followSymlinks": false,
"search.useIgnoreFiles": true,

"C_Cpp.files.exclude": {
"**/.vscode": true,
"src/javascript/jsc/WebKit/JSTests": true,
"src/javascript/jsc/WebKit/Tools": true,
"src/javascript/jsc/WebKit/WebDriverTests": true,
"src/javascript/jsc/WebKit/WebKit.xcworkspace": true,
"src/javascript/jsc/WebKit/WebKitLibraries": true,
"src/javascript/jsc/WebKit/Websites": true,
"src/javascript/jsc/WebKit/resources": true,
"src/javascript/jsc/WebKit/LayoutTests": true,
"src/javascript/jsc/WebKit/ManualTests": true,
"src/javascript/jsc/WebKit/PerformanceTests": true,
"src/javascript/jsc/WebKit/WebKitLegacy": true,
"src/javascript/jsc/WebKit/WebCore": true,
"src/javascript/jsc/WebKit/WebDriver": true,
"src/javascript/jsc/WebKit/WebKitBuild": true,
"src/javascript/jsc/WebKit/WebInspectorUI": true
},
"files.associations": {
"*.idl": "cpp"
}
}
33 changes: 32 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,38 @@ speedy: speedy-prod-native speedy-prod-wasi speedy-prod-wasm
api:
peechy --schema src/api/schema.peechy --esm src/api/schema.js --ts src/api/schema.d.ts --zig src/api/schema.zig


jsc:
jsc-mac

jsc-mac: jsc-build-mac jsc-bindings-mac

jsc-build-mac:
cd src/javascript/jsc/WebKit && ICU_INCLUDE_DIRS="/usr/local/opt/icu4c/include" ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo" && echo "Ignore the \"has no symbols\" errors"

SRC_DIR := src/javascript/jsc/bindings
OBJ_DIR := src/javascript/jsc/bindings-obj
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES))

jsc-bindings-mac: $(OBJ_FILES)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
clang++ -c -o $@ $< \
-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders \
-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/WTF/Headers \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers \
-DSTATICALLY_LINKED_WITH_JavaScriptCore=1 \
-DSTATICALLY_LINKED_WITH_WTF=1 \
-DBUILDING_WITH_CMAKE=1 \
-DNOMINMAX \
-DENABLE_INSPECTOR_ALTERNATE_DISPATCHERS=0 \
-DBUILDING_JSCONLY__ \
-DASSERT_ENABLED=0\
-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/ \
-Isrc/JavaScript/jsc/bindings/ \
-Isrc/javascript/jsc/WebKit/Source/bmalloc \
-std=gnu++17

speedy-prod-native-macos:
cd src/deps; clang -c picohttpparser.c; cd ../../
zig build -Drelease-fast -Dtarget=x86_64-macos-gnu
Expand Down
146 changes: 100 additions & 46 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ pub fn addPicoHTTP(step: *std.build.LibExeObjStep) void {
.path = .{ .path = "src/deps/picohttp.zig" },
});

step.addObjectFile(
"src/deps/picohttpparser.o",
);
step.addObjectFile("src/deps/picohttpparser.o");
step.addIncludeDir("src/deps");
}
// step.add("/Users/jarred/Code/WebKit/WebKitBuild/Release/lib/libWTF.a");

const ENABLE_JAVASCRIPT_BUILD = false;
// ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON"
// set -gx ICU_INCLUDE_DIRS "/usr/local/opt/icu4c/include"
// homebrew-provided icu4c
}

pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

var cwd_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var cwd = std.os.getFdPath(std.fs.cwd().fd, &cwd_buf) catch unreachable;
const cwd: []const u8 = b.pathFromRoot(".");
var exe: *std.build.LibExeObjStep = undefined;

var output_dir_buf = std.mem.zeroes([4096]u8);
var bin_label = if (mode == std.builtin.Mode.Debug) "/debug/" else "/";
const output_dir = std.fmt.bufPrint(&output_dir_buf, "build{s}{s}-{s}", .{ bin_label, @tagName(target.getOs().tag), @tagName(target.getCpuArch()) }) catch unreachable;
Expand Down Expand Up @@ -70,7 +69,7 @@ pub fn build(b: *std.build.Builder) void {
lib.setTarget(target);
lib.setBuildMode(mode);

std.fs.deleteTreeAbsolute(std.fs.path.join(std.heap.page_allocator, &.{ cwd, lib.getOutputSource().getPath(b) }) catch unreachable) catch {};
std.fs.deleteTreeAbsolute(std.fs.path.join(b.allocator, &.{ cwd, lib.getOutputSource().getPath(b) }) catch unreachable) catch {};
var install = b.getInstallStep();
lib.strip = false;
lib.install();
Expand Down Expand Up @@ -98,7 +97,7 @@ pub fn build(b: *std.build.Builder) void {

exe.setOutputDir(output_dir);

var walker = std.fs.walkPath(std.heap.page_allocator, cwd) catch unreachable;
var walker = std.fs.walkPath(b.allocator, cwd) catch unreachable;
if (std.builtin.is_test) {
while (walker.next() catch unreachable) |entry| {
if (std.mem.endsWith(u8, entry.basename, "_test.zig")) {
Expand All @@ -116,44 +115,102 @@ pub fn build(b: *std.build.Builder) void {
exe.setTarget(target);
exe.setBuildMode(mode);
b.install_path = output_dir;
var javascript: @TypeOf(exe) = undefined;

var javascript = b.addExecutable("spjs", "src/main_javascript.zig");
var typings_exe = b.addExecutable("typescript-decls", "src/javascript/jsc/typescript.zig");

// exe.want_lto = true;
if (!target.getCpuArch().isWasm()) {
addPicoHTTP(
exe,
);
if (ENABLE_JAVASCRIPT_BUILD) {
javascript = b.addExecutable("spjs", "src/main_javascript.zig");
b.default_step.dependOn(&exe.step);

const bindings_dir = std.fs.path.join(
b.allocator,
&.{
cwd,
"src",
"javascript",
"jsc",
"bindings-obj",
},
) catch unreachable;

var bindings_walker = std.fs.walkPath(b.allocator, bindings_dir) catch unreachable;
var bindings_files = std.ArrayList([]const u8).init(b.allocator);

while (bindings_walker.next() catch unreachable) |entry| {
if (std.mem.eql(u8, std.fs.path.extension(entry.basename), ".o")) {
bindings_files.append(b.allocator.dupe(u8, entry.path) catch unreachable) catch unreachable;
}
}

// // References:
// // - https://github.com/mceSystems/node-jsc/blob/master/deps/jscshim/webkit.gyp
// // - https://github.com/mceSystems/node-jsc/blob/master/deps/jscshim/docs/webkit_fork_and_compilation.md#webkit-port-and-compilation
// const flags = [_][]const u8{
// "-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders",
// "-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/WTF/Headers",
// "-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers",
// "-DSTATICALLY_LINKED_WITH_JavaScriptCore=1",
// "-DSTATICALLY_LINKED_WITH_WTF=1",
// "-DBUILDING_WITH_CMAKE=1",
// "-DNOMINMAX",
// "-DENABLE_INSPECTOR_ALTERNATE_DISPATCHERS=0",
// "-DBUILDING_JSCONLY__",
// "-DASSERT_ENABLED=0", // missing symbol errors like this will happen "JSC::DFG::DoesGCCheck::verifyCanGC(JSC::VM&)"
// "-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/", // config.h,
// "-Isrc/JavaScript/jsc/bindings/",
// "-Isrc/javascript/jsc/WebKit/Source/bmalloc",
// "-std=gnu++17",
// if (target.getOsTag() == .macos) "-DUSE_FOUNDATION=1" else "",
// if (target.getOsTag() == .macos) "-DUSE_CF_RETAIN_PTR=1" else "",
// };
const headers_step = b.step("headers", "JSC headers");
var headers_exec: *std.build.LibExeObjStep = b.addExecutable("headers", "src/javascript/jsc/bindings/bindings-generator.zig");
var headers_runner = headers_exec.run();
headers_step.dependOn(&headers_runner.step);

b.default_step.dependOn(&exe.step);

var steps = [_]*std.build.LibExeObjStep{ exe, javascript, typings_exe };

for (steps) |step| {
step.linkLibC();
step.linkLibCpp();
addPicoHTTP(
javascript,
step,
);
javascript.packages = std.ArrayList(std.build.Pkg).fromOwnedSlice(std.heap.page_allocator, std.heap.page_allocator.dupe(std.build.Pkg, exe.packages.items) catch unreachable);
javascript.setOutputDir(output_dir);
javascript.setBuildMode(mode);
javascript.linkLibC();
}

// javascript.linkLibCpp();
step.addObjectFile("src/JavaScript/jsc/WebKit/WebKitBuild/Release/lib/libJavaScriptCore.a");
step.addObjectFile("src/JavaScript/jsc/WebKit/WebKitBuild/Release/lib/libWTF.a");
step.addObjectFile("src/JavaScript/jsc/WebKit/WebKitBuild/Release/lib/libbmalloc.a");

if (target.getOsTag() == .macos) {
if (ENABLE_JAVASCRIPT_BUILD) {
javascript.linkFramework("JavaScriptCore");
}
exe.linkFramework("JavascriptCore");
}
if (ENABLE_JAVASCRIPT_BUILD) {
javascript.strip = false;
}
}
// We must link ICU statically
step.addObjectFile("/usr/local/opt/icu4c/lib/libicudata.a");
step.addObjectFile("/usr/local/opt/icu4c/lib/libicui18n.a");
step.addObjectFile("/usr/local/opt/icu4c/lib/libicuuc.a");

b.default_step.dependOn(&exe.step);
if (target.getOsTag() == .macos) {
// icucore is a weird macOS only library
step.linkSystemLibrary("icucore");
step.addLibPath("/usr/local/opt/icu4c/lib");
step.addIncludeDir("/usr/local/opt/icu4c/include");
}

if (!target.getCpuArch().isWasm()) {
if (ENABLE_JAVASCRIPT_BUILD) {
javascript.install();
for (bindings_files.items) |binding| {
step.addObjectFile(
binding,
);
}
}
} else {
b.default_step.dependOn(&exe.step);
}

javascript.strip = false;
javascript.packages = std.ArrayList(std.build.Pkg).fromOwnedSlice(b.allocator, b.allocator.dupe(std.build.Pkg, exe.packages.items) catch unreachable);
javascript.setOutputDir(output_dir);
javascript.setBuildMode(mode);

const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
Expand All @@ -166,22 +223,19 @@ pub fn build(b: *std.build.Builder) void {
var log_step = b.addLog("Destination: {s}/{s}\n", .{ output_dir, "esdev" });
log_step.step.dependOn(&exe.step);

var typings_exe = b.addExecutable("typescript-decls", "src/javascript/jsc/typescript.zig");
var typings_cmd: *std.build.RunStep = typings_exe.run();
typings_cmd.cwd = cwd;
typings_cmd.addArg(cwd);
typings_cmd.addArg("types");

typings_cmd.step.dependOn(&typings_exe.step);

typings_exe.linkLibC();
typings_exe.linkLibCpp();
typings_exe.setMainPkgPath(cwd);
if (target.getOsTag() == .macos) {
typings_exe.linkFramework("JavascriptCore");
}
addPicoHTTP(
typings_exe,
);
const typings_step = b.step("types", "Build TypeScript types");

var typings_step = b.step("types", "Build TypeScript types");
typings_step.dependOn(&typings_cmd.step);

var javascript_cmd = b.step("spjs", "Build standalone JavaScript runtime. Must run \"make jsc\" first.");
javascript_cmd.dependOn(&javascript.step);
}
3 changes: 3 additions & 0 deletions src/feature_flags.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ pub const CSSModulePolyfill = enum {
// Just return whatever the property key they referenced was
facade,
};

// having issues compiling WebKit with this enabled
pub const remote_inspector = false;
4 changes: 2 additions & 2 deletions src/global.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub usingnamespace @import("env.zig");
pub const FeatureFlags = @import("feature_flags.zig");

pub const Output = struct {
threadlocal var source: *Source = undefined;
threadlocal var source: Source = undefined;
pub const Source = struct {
const StreamType = {
if (isWasm) {
Expand Down Expand Up @@ -41,7 +41,7 @@ pub const Output = struct {
}

pub fn set(_source: *Source) void {
source = _source;
source = _source.*;
}
};
pub var enable_ansi_colors = isNative;
Expand Down
3 changes: 2 additions & 1 deletion src/http.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ threadlocal var res_headers_buf: [100]picohttp.Header = undefined;
const sync = @import("./sync.zig");
const JavaScript = @import("./javascript/jsc/JavaScript.zig");
const js = @import("javascript/jsc/javascript.zig");

const Router = @import("./router.zig");
pub const Watcher = watcher.NewWatcher(*Server);

const ENABLE_LOGGER = false;
Expand Down Expand Up @@ -193,6 +193,7 @@ pub const RequestContext = struct {
controlled: bool = false,
watcher: *Watcher,
timer: std.time.Timer,
matched_route: ?Router.Match = null,

full_url: [:0]const u8 = "",
res_headers_count: usize = 0,
Expand Down
Loading

0 comments on commit 79cd2fb

Please sign in to comment.