Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add revery #954

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
34 changes: 34 additions & 0 deletions ocaml/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
, libxcb
, xorg
, zstd-oc
, libfontconfig
}:

oself: osuper:
Expand Down Expand Up @@ -1584,6 +1585,39 @@ with oself;
};
});

reason-harfbuzz = callPackage ./revery/reason-harfbuzz.nix { };
reason-sdl2 = callPackage ./revery/reason-sdl2.nix { };
reason-skia = callPackage ./revery/reason-skia.nix {
inherit libfontconfig;
};
revery = callPackage ./revery { };

rench = buildDunePackage {
pname = "Rench";
version = "0.0.0";
src = fetchFromGitHub {
owner = "revery-ui";
repo = "rench";
rev = "df44c5277ed1d3ccfa959f2623705baefd26ad99";
sha256 = "sha256-cGBYBIxVIuhbvkGxM1lAN0j5m5Fiqlc3O1xyt9OFP4U=";
};
nativeBuildInputs = [ reason ];
propagatedBuildInputs = [ flex fpath ];
};

timber = buildDunePackage {
pname = "timber";
version = "0.0.0";
src = fetchFromGitHub {
owner = "revery-ui";
repo = "timber";
rev = "f4c40ee5d7cb93801160340ac4ac9c974ce01b66";
sha256 = "sha256-tk/2Of0R4WzjM7Fiv0mXVSbmiRHXMtppLgBcgvX4p9s=";
};
nativeBuildInputs = [ reason ];
propagatedBuildInputs = [ fmt logs re ];
};

swhid_core = buildDunePackage {
pname = "swhid_core";
version = "0.1";
Expand Down
85 changes: 85 additions & 0 deletions ocaml/revery/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{ lib
, buildDunePackage
, fetchFromGitHub
, dune-configurator
, pkg-config
, reason
, lru
, uchar
, ppx_deriving
, brisk-reconciler
, lwt_ppx
, ppx_optcomp
, uutf
, uucp
, rebez
, bos
, charInfo_width
, reason-sdl2
, reason-skia
, reason-harfbuzz
, rench
, timber
}:

let
# This change is allows configuring initial capacity of the cache
# https://github.com/pqwy/lru/pull/8/commits/f646450cc5a165bbb39121d5a456dd3f5ad4dba5
lruOverride = lru.overrideAttrs (_: super: {
patches = [ ./patches/0001-lru-initial-size.patch ];
});
omd = buildDunePackage {
pname = "omd";
version = "0.0.0";
src = fetchFromGitHub {
owner = "ocaml";
repo = "omd";
rev = "1535e3c684323f370f3f80bce2564863140de6ba";
sha256 = "sha256-Tu60WdHvVq24m6QMJTe3B55gfNjtoxomW/Q3MT6//n4=";
};
propagatedBuildInputs = [
uchar
];
};

in

buildDunePackage {
pname = "Revery";
version = "0.0.0";
# TODO: check if a patch can avoid disabling this
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-overflow
hardeningDisable = [ "strictoverflow" ];
inherit (reason-sdl2) src;
preBuild = ''
substituteInPlace packages/zed/src/dune --replace "bytes" ""
# This supresses a warning from the use of CAMLparam2, where caml__frame is unused:
# dialog.c:32:5: error: unused variable 'caml__frame' [-Werror,-Wunused-variable]
# TODO: try to suppress this for the single file
substituteInPlace src/Native/dune --replace "-Werror" "-Werror -Wno-unused-variable"
'';
buildInputs = [
dune-configurator
];
nativeBuildInputs = [
reason
pkg-config
];
propagatedBuildInputs = [
ppx_deriving
brisk-reconciler
lwt_ppx
ppx_optcomp
uutf
uucp
reason-skia
omd
rebez
bos
reason-harfbuzz
charInfo_width
lruOverride
rench
timber
];
}
49 changes: 49 additions & 0 deletions ocaml/revery/patches/0001-lru-initial-size.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
diff --git a/src/lru.ml b/src/lru.ml
index f3e1301..fffcec2 100644
--- a/src/lru.ml
+++ b/src/lru.ml
@@ -209,7 +209,7 @@ module M = struct
type t
type k
type v
- val create : ?random:bool -> int -> t
+ val create : ?random:bool -> ?initialSize: int -> int -> t
val is_empty : t -> bool
val size : t -> int
val weight : t -> int
@@ -250,9 +250,11 @@ module M = struct

let cap_makes_sense = cap_makes_sense ~m:"M"

- let create ?random cap =
+ let create ?random ?initialSize cap =
+ let hashSize =
+ match initialSize with | None -> cap | (Some v) -> v in
cap_makes_sense ~f:"create" cap;
- { cap; w = 0; ht = HT.create ?random cap; q = Q.create () }
+ { cap; w = 0; ht = HT.create ?random hashSize; q = Q.create () }

let lru t = match t.q.Q.first with Some n -> Some n.Q.value | _ -> None

diff --git a/src/lru.mli b/src/lru.mli
index 5271846..ea81bf0 100644
--- a/src/lru.mli
+++ b/src/lru.mli
@@ -219,12 +219,15 @@ module M : sig
type v
(** Values in {{!t}[t]}. *)

- val create : ?random:bool -> int -> t
- (** [create ?random cap] is a new map with capacity [cap].
+ val create : ?random:bool -> ?initialSize:int -> int -> t
+ (** [create ?random ?initialSize cap] is a new map with capacity [cap].

[~random] randomizes the underlying hash table. It defaults to [false].
See {!Hashtbl.create}.

+ [~initialSize] sets the initial size of the underlying hash table. If not set,
+ [initialSize] is set to [cap].
+
{b Note.} The internal hash table is created with size [cap].

@raise Invalid_argument when [cap < 0]. *)
52 changes: 52 additions & 0 deletions ocaml/revery/patches/0002-esy-skia-use-libtool.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From 445b2e0cb969f9de458b8464bd3b18caade11fc4 Mon Sep 17 00:00:00 2001
From: Joseph Price <[email protected]>
Date: Wed, 19 Jul 2023 07:37:32 -0400
Subject: [PATCH] use libtool

---
gn/toolchain/BUILD.gn | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/gn/toolchain/BUILD.gn b/gn/toolchain/BUILD.gn
index cd1def114d..8a914a99c3 100644
--- a/gn/toolchain/BUILD.gn
+++ b/gn/toolchain/BUILD.gn
@@ -260,11 +260,22 @@ template("gcc_like_toolchain") {
description = "assemble {{source}}"
}

+ if (is_mac || is_ios) {
+ not_needed([ "ar" ]) # We use libtool instead.
+ }
tool("alink") {
- rspfile = "{{output}}.rsp"
- rspfile_content = "{{inputs}}"
- ar_py = rebase_path("../ar.py")
- command = "python $ar_py $ar {{output}} $rspfile"
+ if (is_mac || is_ios) {
+ command = "libtool -static -o {{output}} -no_warning_for_no_symbols {{inputs}}"
+ } else {
+ rspfile = "{{output}}.rsp"
+ rspfile_content = "{{inputs}}"
+ # TODO: add rm.py
+ #rm_py = rebase_path("../rm.py")
+ #command = "$shell python3 \"$rm_py\" \"{{output}}\" && $ar rcs {{output}} @$rspfile"
+ ar_py = rebase_path("../ar.py")
+ command = "python $ar_py $ar {{output}} $rspfile"
+ }
+
outputs = [
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
]
@@ -280,7 +291,7 @@ template("gcc_like_toolchain") {
}

rpath = "-Wl,-soname,$soname"
- if (is_mac) {
+ if (is_mac || is_ios) {
rpath = "-Wl,-install_name,@rpath/$soname"
}

--
2.40.1

29 changes: 29 additions & 0 deletions ocaml/revery/reason-harfbuzz.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ buildDunePackage
, pkg-config
, reason-sdl2
, reason
, dune-configurator
, harfbuzz
, lib
, libcxx
, stdenv
, darwin
}:

buildDunePackage {
pname = "reason-harfbuzz";
version = "0.0.0";
inherit (reason-sdl2) src;

buildInputs = [ dune-configurator ] ++
lib.optionals stdenv.isDarwin
(with darwin.apple_sdk.frameworks;
lib.optionals stdenv.isDarwin [ Foundation AppKit ]);
nativeBuildInputs = [
reason
pkg-config
];
HARFBUZZ_INCLUDE_PATH = "${harfbuzz.dev}/include/harfbuzz";
HARFBUZZ_LIB_PATH = ''${harfbuzz}/lib'';
NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
}
70 changes: 70 additions & 0 deletions ocaml/revery/reason-sdl2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{ buildDunePackage
, fetchFromGitHub
, SDL2
, ctypes
, findlib
, reason
, dune-configurator
, darwin
, libiconv
, lib
, stdenv
, libcxx
, libGLU
, libXxf86vm
, libXcursor
, libXrandr
, libXinerama
, libXi
}:

buildDunePackage rec {
pname = "reason-sdl2";
version = "0.0.0";
src = fetchFromGitHub {
owner = "revery-ui";
repo = "revery";
# master branch as of Aug 27, 2021
rev = "141f70f69d6abd69674b46d805a783411b38cd79";
sha256 = "sha256-3AGdf0vcFoxcmGUHCUcmjb+VCpp2WDYmkv9Tp7VJqsw=";
};
postPatch = ''
substituteInPlace packages/reason-sdl2/src/sdl2_wrapper.cpp \
--replace "case SDL_PANEVENT:" "/* case SDL_PANEVENT:" \
--replace "case SDL_DROPTEXT:" "*/ case SDL_DROPTEXT:" \
--replace "case SDL_WINDOWEVENT_FULLSCREEN:" "/* case SDL_WINDOWEVENT_FULLSCREEN:" \
--replace "case SDL_WINDOWEVENT_RESTORED:" "*/ case SDL_WINDOWEVENT_RESTORED:" \
--replace "hash_variant" "caml_hash_variant"
'';
buildInputs = [
dune-configurator
# SDL2
# SDL2.dev
libiconv
] ++
lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.ForceFeedback
] ++
lib.optionals stdenv.isLinux [
libGLU
libXxf86vm
libXcursor
libXrandr
libXinerama
libXi
];
nativeBuildInputs = [
reason
findlib
];
propagatedBuildInputs = [
SDL2
SDL2.dev
ctypes
];
SDL2_LIB_PATH = ''${(SDL2.override { withStatic = true; }).out}/lib'';
SDL2_INCLUDE_PATH = "${SDL2.dev}/include";
cur__root = "${src}";
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
}
Loading