From 5c067768d7afa8731817b3f458d25fb3ec337128 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Sat, 26 Oct 2024 20:52:36 +0530 Subject: [PATCH 01/22] (fix) flake: add `pkg-config` as build input --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 00b3e7c..28df224 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,7 @@ ]; buildInputs = with pkgs; [ + pkg-config libxkbcommon libseccomp libGL From 2c5cd8b60509112053d99c875dfd94146b7898f8 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Sun, 27 Oct 2024 10:28:33 +0530 Subject: [PATCH 02/22] (up) nix: update flake lock --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 72f2242..e3d8e8c 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1725194671, - "narHash": "sha256-tLGCFEFTB5TaOKkpfw3iYT9dnk4awTP/q4w+ROpMfuw=", + "lastModified": 1729951556, + "narHash": "sha256-bpb6r3GjzhNW8l+mWtRtLNg5PhJIae041sPyqcFNGb4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b833ff01a0d694b910daca6e2ff4a3f26dee478c", + "rev": "4e0eec54db79d4d0909f45a88037210ff8eaffee", "type": "github" }, "original": { From 9d5ed712febbf338ff0667afe1bbecf7e225896e Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Sun, 27 Oct 2024 10:28:54 +0530 Subject: [PATCH 03/22] (fix) flake: fix env vars in devshell --- flake.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 28df224..8936e5b 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,6 @@ libseccomp libGL glfw - simdutf xorg.libX11 openssl.dev @@ -47,8 +46,14 @@ LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ libGL + simdutf ]; + env = { + # pkg-config cannot find simdutf without this, weird. + PKG_CONFIG_PATH = "${with pkgs; lib.makeLibraryPath [pkgs.simdutf]}/pkgconfig"; + }; + wrapFerus = let makeWrapperArgs = "--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"; From 295c65b14e9d9f1367fd550726468471b1cd236e Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:32:10 +0530 Subject: [PATCH 04/22] (deps) add `bali`, update other deps --- ferus.nimble | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ferus.nimble b/ferus.nimble index 36cb7f1..808882e 100644 --- a/ferus.nimble +++ b/ferus.nimble @@ -11,14 +11,15 @@ bin = @["ferus", "ferus_process"] # Dependencies requires "nim >= 2.0.2" -requires "ferusgfx >= 1.1" +requires "ferusgfx >= 1.1.1" requires "colored_logger >= 0.1.0" requires "stylus >= 0.1.0" -requires "https://github.com/ferus-web/ferus_ipc" +requires "https://github.com/ferus-web/ferus_ipc >= 0.1.2" requires "https://github.com/ferus-web/sanchar" requires "https://git.sr.ht/~bptato/chame >= 0.14.5" requires "seccomp >= 0.2.1" requires "simdutf >= 5.5.0" +requires "https://github.com/ferus-web/bali#master" requires "results" requires "pretty" requires "chagashi >= 0.5.4" From c1c60f7ae2b2d0be6964245be0dcfcbacfb0d8e8 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:32:29 +0530 Subject: [PATCH 05/22] (fix) nim.cfg: fix compiler settings --- nim.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nim.cfg b/nim.cfg index 371181d..aeef1d2 100644 --- a/nim.cfg +++ b/nim.cfg @@ -12,6 +12,7 @@ # -d:ferusAddMangohudToRendererPrefix # -d:ferusJustWaitForConnection -d:ferusUseGlfw +# -d:ferusIpcLogSendsToStdout # glfw flags # -d:glfwStaticLib @@ -20,4 +21,4 @@ # -d:ferusgfxDrawDamagedRegions # Enable SIMD support ---passC: "-march=native -mtune=native -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mpclmul -mavx -mavx2" +--passC: "-march=znver3 -mtune=znver3 -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mpclmul -mavx -mavx2" From b0cb7c8a0259a93a26c96b9f3c5eb88da2e675f0 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:32:44 +0530 Subject: [PATCH 06/22] (add) samples: add javascript sample --- samples/003.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 samples/003.html diff --git a/samples/003.html b/samples/003.html new file mode 100644 index 0000000..715dd1b --- /dev/null +++ b/samples/003.html @@ -0,0 +1,17 @@ + + + + Hello BaliJS! + + + +

Check your console, there must be a few log messages there :^)

+

If there aren't, then something went horribly wrong.

+

+

You should file a bug report in that case.

+ + From 746e4c0b107fa51c15f6b2a7e2aba84b76d0c3b5 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:33:01 +0530 Subject: [PATCH 07/22] (add) components/shared/nix: init This file just houses utilities for *NIX systems --- src/components/shared/nix.nim | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/components/shared/nix.nim diff --git a/src/components/shared/nix.nim b/src/components/shared/nix.nim new file mode 100644 index 0000000..a79417b --- /dev/null +++ b/src/components/shared/nix.nim @@ -0,0 +1,4 @@ +## Shared *NIX utilities + +var FIONREAD* {.importc, header: "".}: cint +proc ioctl*(fd: cint, op: cint, argp: pointer): cint {.importc, header: "".} From 5d69371e01ebbdcfcaff7beb334c686a8da57641 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:33:39 +0530 Subject: [PATCH 08/22] (fix) components/renderer: use `components/shared/nix` --- src/components/renderer/process.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/renderer/process.nim b/src/components/renderer/process.nim index 254fe94..80f9ea6 100644 --- a/src/components/renderer/process.nim +++ b/src/components/renderer/process.nim @@ -6,14 +6,11 @@ when defined(linux): import ../../components/sandbox/linux import ../../components/renderer/[core] -import ../../components/shared/sugar +import ../../components/shared/[nix, sugar] import ../../components/renderer/ipc except newDisplayList {.passL: "-lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon -lGL".} -var FIONREAD {.importc, header: "".}: cint -proc ioctl(fd: cint, op: cint, argp: pointer): cint {.importc, header: "".} - proc readTypeface*(data, format: string): Typeface {.raises: [PixieError].} = ## Loads a typeface from data. try: @@ -116,7 +113,7 @@ proc talk( ) {.inline.} = var count: cint - discard ioctl(client.socket.getFd().cint, FIONREAD, addr count) + discard nix.ioctl(client.socket.getFd().cint, nix.FIONREAD, addr count) if count < 1: return From 8ed50fc8cd71b00a5f9df67a6e2a968a3b02f6a0 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:34:09 +0530 Subject: [PATCH 09/22] (add) components/parsers/html: send invalid JSON data as error --- src/components/parsers/html/process.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/parsers/html/process.nim b/src/components/parsers/html/process.nim index 76c52fa..f44135f 100644 --- a/src/components/parsers/html/process.nim +++ b/src/components/parsers/html/process.nim @@ -35,6 +35,7 @@ proc talk(client: var IPCClient, process: FerusProcess) {.inline.} = if not *jdata: warn "Did not get any valid JSON data." + warn data return let kind = (&jdata).getOrDefault("kind").getStr().magicFromStr() From 1decfce74d01cbb83e3869b77cd29618a09f99ba Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:34:43 +0530 Subject: [PATCH 10/22] (add) components/network: send invalid data as error --- src/components/network/process.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/network/process.nim b/src/components/network/process.nim index bdc16fb..4a13770 100644 --- a/src/components/network/process.nim +++ b/src/components/network/process.nim @@ -52,6 +52,7 @@ proc talk(client: var IPCClient, process: FerusProcess) {.inline.} = if not *jdata: warn "Did not get any valid JSON data." + warn data return let kind = (&jdata).getOrDefault("kind").getStr().magicFromStr() From 59f13fd80d278e38f8c97204e2915d0474566471 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Mon, 28 Oct 2024 20:35:12 +0530 Subject: [PATCH 11/22] (fix) components/layout: ignore `

Check your console, there must be a few log messages there :^)

-

If there aren't, then something went horribly wrong.

-

-

You should file a bug report in that case.

diff --git a/src/components/js/process.nim b/src/components/js/process.nim index 8c2153f..87cf3c5 100644 --- a/src/components/js/process.nim +++ b/src/components/js/process.nim @@ -51,7 +51,7 @@ proc talk(js: var JSProcess, process: FerusProcess) = info "Executing JavaScript buffer" js.ipc.setState(Processing) let data = &tryParseJson(data, JSExecPacket) - + js.parser = newParser(data.buffer.decode()) js.runtime = newRuntime(data.name.decode(), js.parser.parse()) js.runtime.run() From 970b4d77e04fb6042ffca923a8f6212fbf5e0a40 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Tue, 29 Oct 2024 06:06:04 +0530 Subject: [PATCH 20/22] (fix) ferus_process: temporarily disable IPC logger --- src/ferus_process.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ferus_process.nim b/src/ferus_process.nim index 969ef90..403a951 100644 --- a/src/ferus_process.nim +++ b/src/ferus_process.nim @@ -59,7 +59,7 @@ proc main() {.inline.} = discard client.connect(path) client.handshake() - addHandler newIPCLogger(lvlAll, client) + # addHandler newIPCLogger(lvlAll, client) setLogFilter(lvlInfo) if process.kind != Renderer: From 9e01ee84bea7410d4f64d50f1f8f17556f613552 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Tue, 29 Oct 2024 06:10:55 +0530 Subject: [PATCH 21/22] (deps) add jsony --- ferus.nimble | 1 + 1 file changed, 1 insertion(+) diff --git a/ferus.nimble b/ferus.nimble index 3cb3ed5..efae8a4 100644 --- a/ferus.nimble +++ b/ferus.nimble @@ -22,6 +22,7 @@ requires "simdutf >= 5.5.0" requires "https://github.com/ferus-web/bali#master" requires "results" requires "pretty" +requires "jsony >= 1.1.5" requires "chagashi >= 0.5.4" when defined(ferusUseGlfw): From 86e9e486b8d2a7f3310a4601278cbaaadb1030e6 Mon Sep 17 00:00:00 2001 From: xTrayambak Date: Tue, 29 Oct 2024 06:12:46 +0530 Subject: [PATCH 22/22] (xxx) update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cec052..bdc2e9b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # The Ferus Web Engine -The Ferus web engine is a tiny web engine written in Nim which aims to be a full replacement for something like Chromium's Blink, Safari's WebKit or Firefox's Gecko. +The Ferus web engine is a tiny web engine written in Nim which aims to be a full replacement for something like Chromium's Blink, Safari's WebKit or Firefox's Gecko. \ +It has rudimentary support for layout and JavaScript. ![A screenshot of Ferus rendering nim-lang.org](screenshots/ferus_nimlang.jpg) # Features - When possible, we write our own solution to a component of the overall modern web stack. This has resulted in projects like Stylus (our CSS3 compliant parser derived from Servo) and Bali (our JavaScript engine based on Mirage, our bytecode interpreter) and Sanchar (our HTTP client and URL parser) that are beneficial for the overall Nim community. +- Ferus has some initial JavaScript support. Our JavaScript engine is hovering around 2% of passing tests in Test262, so don't expect to be able to daily drive Ferus! + - Maximizing security will be our number one priority once we're past the toy engine stage. We have a sandbox that (mostly) works, but it has been disabled by default for the sake of everyone's (mostly our) sanity. If you want to try it out (and improve it), uncomment `-d:ferusInJail` in `nim.cfg`. - Everything is multiprocessed. This ensures that an error in one component (say, the JavaScript engine) won't bring down the entire session* @@ -29,7 +32,7 @@ So far, - Getting Mirage up to speed [X] - Finalizing Stylus' API [X] - Layout compliance -- Implementing the JavaScript runtime process component +- Implementing the JavaScript runtime process component [X] ## Reality check on the progress I started this project when I was 14 to learn how the web works. It took me a while to learn a lot of things about the web (and I appreciate that!). I'm not some ex-WebKit/Blink/Gecko contributor or anything like that. My experience is currently fairly limited in web engine development. \