Skip to content

Commit

Permalink
compile fribidi on Windows as part of platform layer build
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfouilleul committed Nov 6, 2024
1 parent 0ac55cd commit b099016
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 72 deletions.
92 changes: 66 additions & 26 deletions scripts/dev.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import glob
import os
import sys
import sysconfig
import platform
import re
import urllib.request
Expand Down Expand Up @@ -570,26 +571,60 @@ def build_fribidi(release=False):
############################################################
#TODO: sort out what we should do on Windows
############################################################
subprocess.run([
"./autogen.sh"
], check=True)
if platform.system() == "Windows":
pythonScriptsPath = sysconfig.get_path('scripts', f'{os.name}_user')
meson = os.path.join(pythonScriptsPath, "meson.exe")

subprocess.run([
"./configure"
], check=True)
if not os.path.exists(meson):
print("meson not found, installing...")
subprocess.run([
"pip install meson"
], check=True)

subprocess.run([
"make"
], check=True)
yeetdir("build")

# fix install name for macOS
if platform.system() == "Darwin":
subprocess.run([
"install_name_tool",
"-id", "libfribidi.dylib",
"lib/.libs/libfribidi.dylib",
meson, "setup", "build", "-Ddocs=false"
], check=True)

subprocess.run([
meson, "compile", "-C", "build"
], check=True)

# meson puts stuff in build/lib, copy it over to the same place as its put on mac
os.makedirs("lib/.libs", exist_ok=True)

shutil.copy("build/lib/fribidi-0.dll", "lib/.libs/")
shutil.copy("build/lib/fribidi.lib", "lib/.libs/")
shutil.copy("build/config.h", ".")
shutil.copy("build/lib/fribidi-config.h", "lib")

for f in glob.glob("build/gen.tab/*.i"):
shutil.copy(f, ".")

shutil.copy("build/gen.tab/fribidi-unicode-version.h", "lib")

else:
subprocess.run([
"./autogen.sh"
], check=True)

subprocess.run([
"./configure"
], check=True)

subprocess.run([
"make"
], check=True)

# fix install name for macOS
if platform.system() == "Darwin":
subprocess.run([
"install_name_tool",
"-id", "libfribidi.dylib",
"lib/.libs/libfribidi.dylib",
], check=True)


# build wasm
clang = 'clang'
Expand All @@ -611,15 +646,20 @@ def build_fribidi(release=False):
subprocess.run([
clang,
"--target=wasm32",
"--no-standard-libraries",
"--no-standard-libraries", "-I../../src/orca-libc/include",
"-mbulk-memory",
"-Wl,--no-entry",
"-Wl,--export-dynamic",
"-Wl,--relocatable",
"-DHAVE_CONFIG_H",
"-DHAVE_STRINGIZE=1",
"-DHAVE_STRING_H=1",
"-DHAVE_STRINGS_H=1",
"-DHAVE_MEMMOVE",
"-DHAVE_MEMSET",
"-DHAVE_STDLIB_H=1",
"-DHAVE_STRDUP",
"-I.",
"-Ilib",
"-I../../src/orca-libc/include",
*source_files,
"-o", "libfribidi_wasm.a",
], check=True)
Expand All @@ -631,15 +671,15 @@ def build_fribidi(release=False):
sums = []

if platform.system() == "Windows":
shutil.copy("build/fribidi/lib/.libs/libfribidi.dll", "build/fribidi.out/bin")
shutil.copy("build/fribidi/lib/.libs/fribidi-0.dll", "build/fribidi.out/bin")
sums.append({
"file": "bin/libfribidi.dll",
"sum": checksum.filesum("build/fribidi.out/bin/libfribidi.dll")
"file": "bin/fribidi-0.dll",
"sum": checksum.filesum("build/fribidi.out/bin/fribidi-0.dll")
})
shutil.copy("build/fribidi/lib/.libs/libfribidi.dll.lib", "build/fribidi.out/bin")
shutil.copy("build/fribidi/lib/.libs/fribidi.lib", "build/fribidi.out/bin")
sums.append({
"file": "bin/libfribidi.dll.lib",
"sum": checksum.filesum("build/fribidi.out/bin/libfribidi.dll.lib")
"file": "bin/fribidi.lib",
"sum": checksum.filesum("build/fribidi.out/bin/fribidi.lib")
})
else:
shutil.copy("build/fribidi/lib/.libs/libfribidi.dylib", "build/fribidi.out/bin")
Expand Down Expand Up @@ -1131,8 +1171,8 @@ def build_platform_layer_lib_win(release):
"/DELAYLOAD:webgpu.dll",
"libharfbuzz.dll.lib",
"/DELAYLOAD:libharfbuzz.dll",
"libfribidi.dll.lib",
"/DELAYLOAD:libfribidi.dll",
"fribidi.lib",
"/DELAYLOAD:fribidi-0.dll",
]

debug_flags = ["/O2", "/Zi"] if release else ["/Zi", "/DOC_DEBUG", "/DOC_LOG_COMPILE_DEBUG"]
Expand Down Expand Up @@ -1645,7 +1685,7 @@ def package_sdk_internal(dest, target):
shutil.copy(os.path.join("build", "bin", "libGLESv2.dll"), bin_dir)
shutil.copy(os.path.join("build", "bin", "webgpu.dll"), bin_dir)
shutil.copy(os.path.join("build", "bin", "libharfbuzz.dll"), bin_dir)
shutil.copy(os.path.join("build", "bin", "libfribidi.dll"), bin_dir)
shutil.copy(os.path.join("build", "bin", "fribidi-0.dll"), bin_dir)
else:
shutil.copy(os.path.join("build", "bin", "orca"), bin_dir)
shutil.copy(os.path.join("build", "bin", "orca_runtime"), bin_dir)
Expand Down
1 change: 1 addition & 0 deletions sketches/text-layout/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% mai
copy ..\..\build\bin\orca.dll bin
copy ..\..\build\bin\webgpu.dll bin
copy ..\..\build\bin\libharfbuzz.dll bin
copy ..\..\build\bin\fribidi-0.dll bin
52 changes: 11 additions & 41 deletions sketches/text-layout/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,38 +210,7 @@ int main()

{
oc_move_to(origin.x, origin.y);
oc_set_color_rgba(0, 0, 0, 1);

/*
oc_str32 codepoints = oc_utf8_push_to_codepoints(scratch.arena, text);
oc_glyph_run* run = oc_text_shape(scratch.arena, zapFont, 0, codepoints, 0, codepoints.len);
oc_text_draw_run(run, fontSize);

if(mouseClicked)
{
cursor = oc_glyph_run_point_to_cursor(run, fontSize, oc_vec2_sub(mousePoint, origin));
}
//TODO: move to next/prev utf8 char.
//TODO: when we do grapheme segmentation, move to next grapheme
if(moveCursor == 1 && cursor <= text.len)
{
cursor = oc_min(cursor + 1, text.len);
}
else if(moveCursor == -1 && cursor > 0)
{
cursor--;
}
oc_vec2 pos = oc_glyph_run_cursor_to_point(run, fontSize, cursor);
oc_move_to(origin.x + pos.x, origin.y + pos.y + metrics.descent);
oc_line_to(origin.x + pos.x, origin.y + pos.y - metrics.ascent);
oc_set_color_rgba(0, 0, 0, 1);
oc_set_width(1);
oc_stroke();
//oc_text_draw_utf8(text, font, fontSize);
*/
oc_text_line* line = oc_text_line_from_utf8(scratch.arena,
text,
&(oc_text_attributes){
Expand Down Expand Up @@ -276,6 +245,7 @@ int main()
oc_stroke();
}

/*
{
oc_move_to(200, 300);
oc_line_to(300, 300);
Expand All @@ -290,7 +260,7 @@ int main()
oc_str32 codepoints = oc_utf8_push_to_codepoints(scratch.arena, OC_STR8("以呂波耳本部止"));
oc_glyph_run* run = oc_text_shape(scratch.arena,
oc_text_run* run = oc_text_shape(scratch.arena,
japaneseFont,
&(oc_text_shape_settings){
.direction = OC_TEXT_DIRECTION_TTB,
Expand Down Expand Up @@ -333,6 +303,7 @@ int main()
oc_set_text_flip(false);
oc_matrix_pop();
}
*/

{
oc_move_to(500, 400);
Expand All @@ -347,15 +318,14 @@ int main()

oc_str32 codepoints = oc_utf8_push_to_codepoints(scratch.arena, OC_STR8("مرحبا"));

oc_glyph_run* run = oc_text_shape(scratch.arena,
arabicFont,
&(oc_text_shape_settings){
.direction = OC_TEXT_DIRECTION_RTL,
},
codepoints,
0,
codepoints.len);
oc_text_draw_run(run, fontSize);
oc_text_line* line = oc_text_line_from_utf32(scratch.arena,
codepoints,
&(oc_text_attributes){
.font = arabicFont,
.fontSize = fontSize,
.color = { 0, 0, 0, 1 },
});
oc_text_line_draw(line);
}

{
Expand Down
4 changes: 4 additions & 0 deletions sketches/ui/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ set INCLUDES=/I ..\..\src /I ..\..\src\util /I ..\..\src\platform /I ../../ext /

if not exist "bin" mkdir bin
cl /we4013 /Zi /Zc:preprocessor /std:c11 /experimental:c11atomics %INCLUDES% main.c /link /LIBPATH:../../build/bin orca.dll.lib /out:bin/example_ui.exe

copy ..\..\build\bin\orca.dll bin
copy ..\..\build\bin\webgpu.dll bin
copy ..\..\build\bin\libharfbuzz.dll bin
copy ..\..\build\bin\fribidi-0.dll bin
2 changes: 1 addition & 1 deletion sketches/ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cmd command = CMD_NONE;

void log_push(const char* line)
{
oc_str8_list_push(&logArena, &logLines, (oc_str8)OC_STR8(line));
oc_str8_list_push(&logArena, &logLines, OC_STR8(line));
}

void log_pushf(const char* format, ...)
Expand Down
4 changes: 2 additions & 2 deletions src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -4386,7 +4386,7 @@ oc_ui_palette OC_UI_DARK_PALETTE = {
.white = { 1, 1, 1, 1, OC_COLOR_SPACE_SRGB }
};

oc_ui_theme OC_UI_DARK_THEME = {
ORCA_API oc_ui_theme OC_UI_DARK_THEME = {
.white = { 0.894, 0.906, 0.961, 1, OC_COLOR_SPACE_SRGB },
.primary = { 0.33, 0.66, 1, 1, OC_COLOR_SPACE_SRGB }, // blue5
.primaryHover = { 0.5, 0.757, 1, 1, OC_COLOR_SPACE_SRGB }, // blue6
Expand Down Expand Up @@ -4577,7 +4577,7 @@ oc_ui_palette OC_UI_LIGHT_PALETTE = {
.white = { 1, 1, 1, 1, OC_COLOR_SPACE_SRGB }
};

oc_ui_theme OC_UI_LIGHT_THEME = {
ORCA_API oc_ui_theme OC_UI_LIGHT_THEME = {
.white = { 1, 1, 1, 1, OC_COLOR_SPACE_SRGB },
.primary = { 0.000, 0.392, 0.980, 1, OC_COLOR_SPACE_SRGB }, // blue5
.primaryHover = { 0.000, 0.384, 0.839, 1, OC_COLOR_SPACE_SRGB }, // blue6
Expand Down
4 changes: 2 additions & 2 deletions src/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ typedef struct oc_ui_theme
oc_ui_palette* palette;
} oc_ui_theme;

extern oc_ui_theme OC_UI_DARK_THEME;
extern oc_ui_theme OC_UI_LIGHT_THEME;
ORCA_API extern oc_ui_theme OC_UI_DARK_THEME;
ORCA_API extern oc_ui_theme OC_UI_LIGHT_THEME;

typedef struct oc_ui_tag
{
Expand Down

0 comments on commit b099016

Please sign in to comment.