Skip to content

Commit d7c1e3d

Browse files
committed
Move stb dependency into third_party directory
1 parent e92fe8e commit d7c1e3d

File tree

5 files changed

+232
-5
lines changed

5 files changed

+232
-5
lines changed

MODULE.bazel

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ git_override(
1313

1414
module(name = "pixelmatch-cpp17", repo_name = "pixelmatch-cpp17", version = "1.0.1")
1515

16+
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
17+
1618
#
1719
# Build dependencies
1820
#
@@ -22,11 +24,11 @@ bazel_dep(name = "rules_cc", version = "0.1.1")
2224
# Test dependencies
2325
#
2426
bazel_dep(name = "googletest", repo_name = "com_google_gtest", version = "1.17.0", dev_dependency = True)
25-
bazel_dep(name = "stb", version = "0.0.0", dev_dependency = True)
26-
git_override(
27-
module_name = "stb",
28-
remote = "https://github.com/jwmcglynn/rules_stb",
29-
commit = "075e5a470e31e46a7318cc308c79dba205a6b2eb",
27+
28+
new_local_repository(
29+
name = "stb",
30+
build_file = "//third_party:BUILD.stb",
31+
path = "third_party/stb",
3032
)
3133

3234
#

tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cc_fuzz_test(
4343
srcs = ["pixelmatch_fuzzer.cc"],
4444
linkopts = ["-lm"],
4545
tags = [
46+
"manual",
4647
"nocoverage",
4748
],
4849
deps = [

third_party/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exports_files(
2+
# buildifier: keep sorted
3+
[
4+
"BUILD.stb",
5+
],
6+
)

third_party/BUILD.stb

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
load("@pixelmatch-cpp17//third_party:stb.bzl", "stb_library")
2+
3+
STB_COPTS = [
4+
"-Wno-unused-function",
5+
"-Wno-self-assign",
6+
]
7+
8+
stb_library(
9+
name = "c_lexer",
10+
copts = STB_COPTS,
11+
emit_definition_macro = "STB_C_LEXER_IMPLEMENTATION",
12+
)
13+
14+
#
15+
# Note that this needs to be instantiated by following the instructions in stb_connected_components.h
16+
#
17+
# In one source file, create the implementation by doing something like this:
18+
#
19+
# #define STBCC_GRID_COUNT_X_LOG2 10
20+
# #define STBCC_GRID_COUNT_Y_LOG2 10
21+
# #define STB_CONNECTED_COMPONENTS_IMPLEMENTATION
22+
# #include "stb_connected_components.h"
23+
#
24+
stb_library(
25+
name = "connected_components",
26+
copts = STB_COPTS,
27+
)
28+
29+
stb_library(
30+
name = "divide",
31+
copts = STB_COPTS,
32+
emit_definition_macro = "STB_DIVIDE_IMPLEMENTATION",
33+
)
34+
35+
stb_library(
36+
name = "ds",
37+
copts = STB_COPTS,
38+
emit_definition_macro = "STB_DS_IMPLEMENTATION",
39+
)
40+
41+
stb_library(
42+
name = "dxt",
43+
copts = STB_COPTS,
44+
definition_includes = ["memory.h"],
45+
emit_definition_macro = "STB_DXT_IMPLEMENTATION",
46+
)
47+
48+
stb_library(
49+
name = "easy_font",
50+
copts = STB_COPTS,
51+
emit_definition_macro = "STB_EASY_FONT_IMPLEMENTATION",
52+
)
53+
54+
stb_library(
55+
name = "herringbone_wang_tile",
56+
copts = STB_COPTS,
57+
emit_definition_macro = "STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION",
58+
)
59+
60+
stb_library(
61+
name = "hexwave",
62+
copts = STB_COPTS,
63+
emit_definition_macro = "STB_HEXWAVE_IMPLEMENTATION",
64+
)
65+
66+
stb_library(
67+
name = "image",
68+
copts = STB_COPTS,
69+
emit_definition_macro = "STB_IMAGE_IMPLEMENTATION",
70+
)
71+
72+
stb_library(
73+
name = "image_resize2",
74+
copts = STB_COPTS,
75+
emit_definition_macro = "STB_IMAGE_RESIZE_IMPLEMENTATION",
76+
)
77+
78+
stb_library(
79+
name = "image_write",
80+
copts = STB_COPTS,
81+
emit_definition_macro = "STB_IMAGE_WRITE_IMPLEMENTATION",
82+
)
83+
84+
stb_library(
85+
name = "include",
86+
copts = STB_COPTS,
87+
emit_definition_macro = "STB_INCLUDE_IMPLEMENTATION",
88+
)
89+
90+
stb_library(
91+
name = "leakcheck",
92+
copts = STB_COPTS,
93+
emit_definition_macro = "STB_LEAKCHECK_IMPLEMENTATION",
94+
)
95+
96+
stb_library(
97+
name = "perlin",
98+
copts = STB_COPTS,
99+
emit_definition_macro = "STB_PERLIN_IMPLEMENTATION",
100+
)
101+
102+
stb_library(
103+
name = "rect_pack",
104+
copts = STB_COPTS,
105+
emit_definition_macro = "STB_RECT_PACK_IMPLEMENTATION",
106+
)
107+
108+
stb_library(
109+
name = "sprintf",
110+
copts = STB_COPTS,
111+
emit_definition_macro = "STB_SPRINTF_IMPLEMENTATION",
112+
)
113+
114+
stb_library(
115+
name = "textedit",
116+
copts = STB_COPTS,
117+
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
118+
)
119+
120+
stb_library(
121+
name = "tilemap_editor",
122+
copts = STB_COPTS,
123+
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
124+
)
125+
126+
stb_library(
127+
name = "truetype",
128+
copts = STB_COPTS,
129+
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
130+
)
131+
132+
stb_library(
133+
name = "stretchy_buffer",
134+
stb_prefix = False,
135+
)
136+
137+
# stb_vorbis has a reversed mechanism
138+
genrule(
139+
name = "vorbis_definition",
140+
outs = ["stb_vorbis.cpp"],
141+
cmd = 'echo "#include <stb/{0}>" > $(@D)/{1}'.format(
142+
"stb_vorbis.c",
143+
"stb_vorbis.cpp",
144+
),
145+
visibility = ["//visibility:private"],
146+
)
147+
148+
cc_library(
149+
name = "vorbis-private",
150+
srcs = ["stb_vorbis.c"],
151+
copts = STB_COPTS + ["-Wno-unused-value"],
152+
include_prefix = "stb",
153+
visibility = ["//visibility:private"],
154+
)
155+
156+
cc_library(
157+
name = "vorbis",
158+
defines = ["STB_VORBIS_HEADER_ONLY"],
159+
visibility = ["//visibility:public"],
160+
deps = ["//:vorbis-private"],
161+
)

third_party/stb.bzl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Module for building STB libraries.
3+
This module provides a macro for creating cc_library targets from STB header files.
4+
"""
5+
6+
load("@rules_cc//cc:defs.bzl", "cc_library")
7+
8+
def stb_library(name, emit_definition_macro = "", stb_prefix = True, copts = None, defines = None, definition_includes = None):
9+
"""Creates an STB library target, optionally emitting a definition macro.
10+
11+
Args:
12+
name: Base name of the STB header (e.g., "image", "vorbis").
13+
emit_definition_macro: If non-empty, emits a genrule to define the library.
14+
stb_prefix: If True, prefixes the header file with "stb_".
15+
copts: Additional compiler options (list of strings).
16+
defines: Additional defines for the cc_library.
17+
definition_includes: List of headers to include when emitting definition.
18+
"""
19+
20+
# Avoid mutable default arguments.
21+
if copts == None:
22+
copts = []
23+
if defines == None:
24+
defines = []
25+
if definition_includes == None:
26+
definition_includes = []
27+
definition_name = "{}_definition".format(name)
28+
header_file_name = "{0}{1}.h".format("stb_" if stb_prefix else "", name)
29+
src_file_name = "{}_definition.cpp".format(name)
30+
31+
if emit_definition_macro:
32+
includes = "\n".join(["#include <{}>".format(include) for include in definition_includes] + [""])
33+
34+
# Generate the source file for lib compilation
35+
src_file_content = "{}#define {}\n#include <stb/{}>".format(
36+
includes,
37+
emit_definition_macro,
38+
header_file_name,
39+
)
40+
native.genrule(
41+
name = definition_name,
42+
outs = [src_file_name],
43+
cmd = 'echo "{0}" > $(@D)/{1}'.format(
44+
src_file_content,
45+
src_file_name,
46+
),
47+
visibility = ["//visibility:private"],
48+
)
49+
cc_library(
50+
name = name,
51+
hdrs = ["{}".format(header_file_name)],
52+
include_prefix = "stb",
53+
srcs = [src_file_name] if emit_definition_macro else [],
54+
copts = copts,
55+
defines = defines,
56+
visibility = ["//visibility:public"],
57+
)

0 commit comments

Comments
 (0)