Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 7 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ git_override(

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

new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")

#
# Build dependencies
#
Expand All @@ -22,11 +24,11 @@ bazel_dep(name = "rules_cc", version = "0.1.1")
# Test dependencies
#
bazel_dep(name = "googletest", repo_name = "com_google_gtest", version = "1.17.0", dev_dependency = True)
bazel_dep(name = "stb", version = "0.0.0", dev_dependency = True)
git_override(
module_name = "stb",
remote = "https://github.com/jwmcglynn/rules_stb",
commit = "075e5a470e31e46a7318cc308c79dba205a6b2eb",

new_local_repository(
name = "stb",
build_file = "//third_party:BUILD.stb",
path = "third_party/stb",
)

#
Expand Down
1 change: 1 addition & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cc_fuzz_test(
srcs = ["pixelmatch_fuzzer.cc"],
linkopts = ["-lm"],
tags = [
"manual",
"nocoverage",
],
deps = [
Expand Down
6 changes: 6 additions & 0 deletions third_party/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports_files(
# buildifier: keep sorted
[
"BUILD.stb",
],
)
161 changes: 161 additions & 0 deletions third_party/BUILD.stb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
load("@pixelmatch-cpp17//third_party:stb.bzl", "stb_library")

STB_COPTS = [
"-Wno-unused-function",
"-Wno-self-assign",
]

stb_library(
name = "c_lexer",
copts = STB_COPTS,
emit_definition_macro = "STB_C_LEXER_IMPLEMENTATION",
)

#
# Note that this needs to be instantiated by following the instructions in stb_connected_components.h
#
# In one source file, create the implementation by doing something like this:
#
# #define STBCC_GRID_COUNT_X_LOG2 10
# #define STBCC_GRID_COUNT_Y_LOG2 10
# #define STB_CONNECTED_COMPONENTS_IMPLEMENTATION
# #include "stb_connected_components.h"
#
stb_library(
name = "connected_components",
copts = STB_COPTS,
)

stb_library(
name = "divide",
copts = STB_COPTS,
emit_definition_macro = "STB_DIVIDE_IMPLEMENTATION",
)

stb_library(
name = "ds",
copts = STB_COPTS,
emit_definition_macro = "STB_DS_IMPLEMENTATION",
)

stb_library(
name = "dxt",
copts = STB_COPTS,
definition_includes = ["memory.h"],
emit_definition_macro = "STB_DXT_IMPLEMENTATION",
)

stb_library(
name = "easy_font",
copts = STB_COPTS,
emit_definition_macro = "STB_EASY_FONT_IMPLEMENTATION",
)

stb_library(
name = "herringbone_wang_tile",
copts = STB_COPTS,
emit_definition_macro = "STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION",
)

stb_library(
name = "hexwave",
copts = STB_COPTS,
emit_definition_macro = "STB_HEXWAVE_IMPLEMENTATION",
)

stb_library(
name = "image",
copts = STB_COPTS,
emit_definition_macro = "STB_IMAGE_IMPLEMENTATION",
)

stb_library(
name = "image_resize2",
copts = STB_COPTS,
emit_definition_macro = "STB_IMAGE_RESIZE_IMPLEMENTATION",
)

stb_library(
name = "image_write",
copts = STB_COPTS,
emit_definition_macro = "STB_IMAGE_WRITE_IMPLEMENTATION",
)

stb_library(
name = "include",
copts = STB_COPTS,
emit_definition_macro = "STB_INCLUDE_IMPLEMENTATION",
)

stb_library(
name = "leakcheck",
copts = STB_COPTS,
emit_definition_macro = "STB_LEAKCHECK_IMPLEMENTATION",
)

stb_library(
name = "perlin",
copts = STB_COPTS,
emit_definition_macro = "STB_PERLIN_IMPLEMENTATION",
)

stb_library(
name = "rect_pack",
copts = STB_COPTS,
emit_definition_macro = "STB_RECT_PACK_IMPLEMENTATION",
)

stb_library(
name = "sprintf",
copts = STB_COPTS,
emit_definition_macro = "STB_SPRINTF_IMPLEMENTATION",
)

stb_library(
name = "textedit",
copts = STB_COPTS,
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
)

stb_library(
name = "tilemap_editor",
copts = STB_COPTS,
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
)

stb_library(
name = "truetype",
copts = STB_COPTS,
emit_definition_macro = "STB_TRUETYPE_IMPLEMENTATION",
)

stb_library(
name = "stretchy_buffer",
stb_prefix = False,
)

# stb_vorbis has a reversed mechanism
genrule(
name = "vorbis_definition",
outs = ["stb_vorbis.cpp"],
cmd = 'echo "#include <stb/{0}>" > $(@D)/{1}'.format(
"stb_vorbis.c",
"stb_vorbis.cpp",
),
visibility = ["//visibility:private"],
)

cc_library(
name = "vorbis-private",
srcs = ["stb_vorbis.c"],
copts = STB_COPTS + ["-Wno-unused-value"],
include_prefix = "stb",
visibility = ["//visibility:private"],
)

cc_library(
name = "vorbis",
defines = ["STB_VORBIS_HEADER_ONLY"],
visibility = ["//visibility:public"],
deps = ["//:vorbis-private"],
)
57 changes: 57 additions & 0 deletions third_party/stb.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Module for building STB libraries.
This module provides a macro for creating cc_library targets from STB header files.
"""

load("@rules_cc//cc:defs.bzl", "cc_library")

def stb_library(name, emit_definition_macro = "", stb_prefix = True, copts = None, defines = None, definition_includes = None):
"""Creates an STB library target, optionally emitting a definition macro.

Args:
name: Base name of the STB header (e.g., "image", "vorbis").
emit_definition_macro: If non-empty, emits a genrule to define the library.
stb_prefix: If True, prefixes the header file with "stb_".
copts: Additional compiler options (list of strings).
defines: Additional defines for the cc_library.
definition_includes: List of headers to include when emitting definition.
"""

# Avoid mutable default arguments.
if copts == None:
copts = []
if defines == None:
defines = []
if definition_includes == None:
definition_includes = []
definition_name = "{}_definition".format(name)
header_file_name = "{0}{1}.h".format("stb_" if stb_prefix else "", name)
src_file_name = "{}_definition.cpp".format(name)

if emit_definition_macro:
includes = "\n".join(["#include <{}>".format(include) for include in definition_includes] + [""])

# Generate the source file for lib compilation
src_file_content = "{}#define {}\n#include <stb/{}>".format(
includes,
emit_definition_macro,
header_file_name,
)
native.genrule(
name = definition_name,
outs = [src_file_name],
cmd = 'echo "{0}" > $(@D)/{1}'.format(
src_file_content,
src_file_name,
),
visibility = ["//visibility:private"],
)
cc_library(
name = name,
hdrs = ["{}".format(header_file_name)],
include_prefix = "stb",
srcs = [src_file_name] if emit_definition_macro else [],
copts = copts,
defines = defines,
visibility = ["//visibility:public"],
)
32 changes: 32 additions & 0 deletions third_party/stb/.github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Pull Requests and Issues are both welcome.

# Responsiveness

General priority order is:

* Crashes
* Security issues in stb_image
* Bugs
* Security concerns in other libs
* Warnings
* Enhancements (new features, performance improvement, etc)

Pull requests get priority over Issues. Some pull requests I take
as written; some I modify myself; some I will request changes before
accepting them. Because I've ended up supporting a lot of libraries
(20 as I write this, with more on the way), I am somewhat slow to
address things. Many issues have been around for a long time.

# Pull requests

* 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.)
* Do NOT update the version number in the file. (This just causes conflicts.)
* 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.
* Your change needs to compile as both C and C++. Pre-C99 compilers should be supported (e.g. declare at start of block)

# Specific libraries

I generally do not want new file formats for stb_image because
we are trying to improve its security, so increasing its attack
surface is counter-productive.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: stb_image Doesn't Load Specific Image Correctly
about: if an image displays wrong in your program, and you've verified stb_image is
the problem
title: ''
labels: 1 stb_image
assignees: ''

---

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.

2. *Provide an image that does not load correctly using stb_image* so we can reproduce the problem.

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.
24 changes: 24 additions & 0 deletions third_party/stb/.github/ISSUE_TEMPLATE/2-bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: if you're having trouble using a library, try the support forum instead
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.
20 changes: 20 additions & 0 deletions third_party/stb/.github/ISSUE_TEMPLATE/3-feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 4 enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
5 changes: 5 additions & 0 deletions third_party/stb/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: support forum
url: https://github.com/nothings/stb/discussions/categories/q-a
about: having trouble using an stb library? don't create an issue, post in the forum
6 changes: 6 additions & 0 deletions third_party/stb/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Delete this list before clicking CREATE PULL REQUEST
* 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.)
* Do NOT update the version number in the file. (This just causes conflicts.)
* 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.

If you get something above wrong, don't fret it, it's not the end of the world.
23 changes: 23 additions & 0 deletions third_party/stb/.github/workflows/ci-fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'stb'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'stb'
fuzz-seconds: 900
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure()
with:
name: artifacts
path: ./out/artifacts
3 changes: 3 additions & 0 deletions third_party/stb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.obj
*.exe
Loading