Skip to content

Commit 2dfe1b8

Browse files
authored
Move the stb dependency to be vendored in third_party (#72)
* Squashed 'third_party/stb/' content from commit f58f558 git-subtree-dir: third_party/stb git-subtree-split: f58f558c120e9b32c217290b80bad1a0729fbb2c * Move stb dependency into third_party directory
1 parent 8c8f6a5 commit 2dfe1b8

File tree

435 files changed

+112043
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

435 files changed

+112043
-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+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Pull Requests and Issues are both welcome.
2+
3+
# Responsiveness
4+
5+
General priority order is:
6+
7+
* Crashes
8+
* Security issues in stb_image
9+
* Bugs
10+
* Security concerns in other libs
11+
* Warnings
12+
* Enhancements (new features, performance improvement, etc)
13+
14+
Pull requests get priority over Issues. Some pull requests I take
15+
as written; some I modify myself; some I will request changes before
16+
accepting them. Because I've ended up supporting a lot of libraries
17+
(20 as I write this, with more on the way), I am somewhat slow to
18+
address things. Many issues have been around for a long time.
19+
20+
# Pull requests
21+
22+
* Make sure you're using a special branch just for this pull request. (Sometimes people unknowingly use a default branch, then later update that branch, which updates the pull request with the other changes if it hasn't been merged yet.)
23+
* Do NOT update the version number in the file. (This just causes conflicts.)
24+
* Do add your name to the list of contributors. (Don't worry about the formatting.) I'll try to remember to add it if you don't, but I sometimes forget as it's an extra step.
25+
* Your change needs to compile as both C and C++. Pre-C99 compilers should be supported (e.g. declare at start of block)
26+
27+
# Specific libraries
28+
29+
I generally do not want new file formats for stb_image because
30+
we are trying to improve its security, so increasing its attack
31+
surface is counter-productive.
32+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: stb_image Doesn't Load Specific Image Correctly
3+
about: if an image displays wrong in your program, and you've verified stb_image is
4+
the problem
5+
title: ''
6+
labels: 1 stb_image
7+
assignees: ''
8+
9+
---
10+
11+
1. **Confirm that, after loading the image with stbi_load, you've immediately written it out with stbi_write_png or similar, and that version of the image is also wrong.** If it is correct when written out, the problem is not in stb_image. If it displays wrong in a program you're writing, it's probably your display code. For example, people writing OpenGL programs frequently do not upload or display the image correctly and assume stb_image is at fault even though writing out the image demonstrates that it loads correctly.
12+
13+
2. *Provide an image that does not load correctly using stb_image* so we can reproduce the problem.
14+
15+
3. *Provide an image or description of what part of the image is incorrect and how* so we can be sure we've reproduced the problem correctly.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug report
3+
about: if you're having trouble using a library, try the support forum instead
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: 4 enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: support forum
4+
url: https://github.com/nothings/stb/discussions/categories/q-a
5+
about: having trouble using an stb library? don't create an issue, post in the forum

0 commit comments

Comments
 (0)