-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.zig
153 lines (141 loc) · 4.79 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const std = @import("std");
pub fn build(b: *std.Build) void {
const harfbuzz = b.dependency("harfbuzz", .{}).artifact("harfbuzz");
const sheenbidi = b.dependency("sheenbidi", .{}).artifact("sheenbidi");
const dropflow = b.addExecutable(.{
.name = "dropflow",
.target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .wasi,
}),
.optimize = .ReleaseSmall,
.single_threaded = true
});
dropflow.addCSourceFiles(.{
.files = &.{
"src/dropflow.cc",
"gen/lang-script-database.cc",
"gen/grapheme-break-trie.cc",
"gen/line-break-trie.cc",
"gen/emoji-trie.cc",
"gen/script-trie.cc",
"gen/derived-core-properties-trie.cc",
"gen/emoji-scan.c"
},
.flags = &.{
"-fno-exceptions",
"-fno-rtti",
"-fvisibility-inlines-hidden",
"-flto",
"-Oz",
},
});
dropflow.linkLibrary(harfbuzz);
dropflow.linkLibrary(sheenbidi);
dropflow.linkLibCpp();
dropflow.linkLibC();
// these are values that emscripten was using. emscripten produced both a
// smaller binary and one that required way less memory. copying these
// brought the runtime memory down. don't remember if it affected binary size
dropflow.global_base = 1024;
dropflow.stack_size = 65536;
dropflow.initial_memory = 4 * 1024 * 1024;
dropflow.entry = .disabled;
dropflow.rdynamic = true;
dropflow.import_symbols = true;
dropflow.export_table = true;
dropflow.root_module.export_symbol_names = &.{
"hb_blob_create",
"hb_blob_destroy",
"hb_blob_get_data",
"hb_blob_get_length",
"hb_buffer_add_utf16",
"hb_buffer_add_utf8",
"hb_buffer_create",
"hb_buffer_destroy",
"hb_buffer_get_glyph_infos",
"hb_buffer_get_glyph_positions",
"hb_buffer_get_length",
"hb_buffer_set_length",
"hb_buffer_guess_segment_properties",
"hb_buffer_set_cluster_level",
"hb_buffer_set_direction",
"hb_buffer_set_flags",
"hb_buffer_set_language",
"hb_buffer_set_script",
"hb_face_create",
"hb_face_collect_unicodes",
"hb_face_destroy",
"hb_face_get_upem",
"hb_face_reference_table",
"hb_face_count",
"hb_face_reference_blob",
"hb_font_create",
"hb_font_destroy",
"hb_font_get_extents_for_direction",
"hb_font_glyph_to_string",
"hb_font_set_scale",
"hb_font_set_variations",
"hb_font_get_nominal_glyph",
"hb_style_get_value",
"hb_ot_name_get_utf16",
"hb_glyph_info_get_glyph_flags",
"hb_language_from_string",
"hb_ot_var_get_axis_infos",
"hb_ot_metrics_get_position_with_fallback",
"hb_ot_layout_has_substitution",
"hb_ot_layout_has_positioning",
"hb_ot_layout_table_get_script_tags",
"hb_ot_layout_feature_get_lookups",
"hb_ot_layout_language_get_feature_indexes",
"hb_ot_layout_language_get_feature_tags",
"hb_ot_layout_script_get_language_tags",
"hb_ot_layout_lookup_collect_glyphs",
"hb_ot_layout_language_get_required_feature_index",
"hb_script_from_string",
"hb_set_create",
"hb_set_destroy",
"hb_set_get_population",
"hb_set_next_many",
"hb_set_add",
"hb_set_add_range",
"hb_set_union",
"hb_set_copy",
"hb_set_subtract",
"hb_set_clear",
"hb_set_next",
"hb_set_has",
"hb_shape",
"hbjs_glyph_draw",
"SBAlgorithmCreate",
"SBAlgorithmRelease",
"SBAlgorithmGetParagraphBoundary",
"SBAlgorithmCreateParagraph",
"SBParagraphRelease",
"SBParagraphGetLevelsPtr",
"malloc",
"free",
"free_ptr",
// TODO: why isn't __attribute__((used)) for variables working with zig build?
// too tired and too close to getting this working to care at the moment
"line_break_trie",
"emoji_trie",
"script_trie",
"grapheme_break_trie",
"derived_core_properties_trie",
};
b.installArtifact(dropflow);
const binaryen = b.dependency("binaryen", .{});
const postprocess_wasm = b.addExecutable(.{
.name = "postprocess_wasm",
.root_source_file = b.path("tools/postprocess_wasm.zig"),
.target = b.resolveTargetQuery(.{}),
.optimize = .ReleaseFast,
});
postprocess_wasm.linkLibrary(binaryen.artifact("binaryen"));
const postprocess_wasm_step = b.addRunArtifact(postprocess_wasm);
postprocess_wasm_step.addFileArg(dropflow.getEmittedBin());
const postprocess_wasm_out = postprocess_wasm_step.addOutputFileArg("dropflow.wasm");
const postprocess_wasm_install = b.addInstallFileWithDir(postprocess_wasm_out, .{ .custom = "../dist" }, "dropflow.wasm");
b.getInstallStep().dependOn(&postprocess_wasm_install.step);
}