Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add simdjson to the stack. #982

Merged
merged 1 commit into from
Jan 25, 2025
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ build:msan --copt='-fsanitize-memory-track-origins=2'
build:msan --linkopt='-fsanitize=memory'
build:msan --test_env=MSAN_OPTIONS=color=always:external_symbolizer_path=/nix/store/h6rpdk8nb097diyqk1vsglw9chwgfsjr-llvm-18.1.8/bin/llvm-symbolizer
build:msan --per_file_copt='//toxic[:/]@-UAUDIO,-UVIDEO,-UPYTHON'
# msan doesn't like Go (or Go doesn't like Bazel's msan):
# gcc_traceback.c:15:10: fatal error: 'sanitizer/msan_interface.h' file not found
build:msan --build_tag_filters=-no-san,-haskell,-windows,-macos,-go
build:msan --test_tag_filters=-no-san,-haskell,-windows,-macos,-go

build:tsan --config=sanitizer
build:tsan --features=tsan
Expand Down Expand Up @@ -671,6 +675,7 @@ build --per_file_copt='external/sdl2[:/]@-Wno-pedantic'
build --per_file_copt='external/sdl2[:/]@-Wno-sign-compare'
build --per_file_copt='external/sdl2[:/]@-Wno-tautological-value-range-compare'
build --per_file_copt='external/sdl2[:/]@-Wno-unused-but-set-variable'
build --per_file_copt='external/simdjson[:/]@-Wno-unused-member-function'
build --per_file_copt='external/sqlcipher[:/]@-Wno-atomic-implicit-seq-cst'
build --per_file_copt='external/sqlcipher[:/]@-Wno-cast-function-type-strict'
build --per_file_copt='external/sqlcipher[:/]@-Wno-empty-translation-unit'
Expand Down
84 changes: 83 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,84 @@
BasedOnStyle: Google
---
# Language
Standard: Cpp11

# Indentation
IndentWidth: 4
ContinuationIndentWidth: 4
AccessModifierOffset: -4
IndentCaseLabels: false
NamespaceIndentation: None

# Spacing
UseTab: Never
SpaceBeforeParens: ControlStatements
SpacesBeforeTrailingComments: 1
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInCStyleCastParentheses: false
SpaceBeforeAssignmentOperators: true
MaxEmptyLinesToKeep: 2

# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true

# Argument Packing
BinPackArguments: true
BinPackParameters: true

# Break handling
ColumnLimit: 100
BreakBeforeBraces: Mozilla
BreakBeforeBinaryOperators: NonAssignment
BreakConstructorInitializersBeforeComma: true
AlwaysBreakTemplateDeclarations: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Cpp11BracedListStyle: true

# Break penalities
PenaltyBreakBeforeFirstCallParameter: 200
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 5
PenaltyReturnTypeOnItsOwnLine: 60

# Includes
SortIncludes: true
IncludeIsMainRegex: '([-_](test|fuzz_test))?$'
IncludeBlocks: Regroup
IncludeCategories:
# Match local headers
- Regex: '^"[[:alnum:]_]+\.h"$'
Priority: 1
# Match project headers
- Regex: '^"[[:alnum:]_]+/.+\.h"$'
Priority: 2
# Match Qt headers
- Regex: '^<Q[[:alnum:]_/]+>$'
Priority: 3
# Match other headers
- Regex: '.*'
Priority: 4

# Short blocks
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty

# Set pointer format
DerivePointerAlignment: false
PointerAlignment: Left

# "const X" instead of "X const"
QualifierAlignment: Left
...
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ jobs:
- name: Build toxchat/toktok-stack:latest
run: docker build -t toxchat/toktok-stack:latest -f tools/built/src/Dockerfile .

- name: Build toxchat/toktok-stack:latest-msan
run: |
docker build -t toxchat/toktok-stack:latest-msan -f tools/built/src/Dockerfile.msan .
docker rmi toxchat/toktok-stack:latest-msan
docker system prune -f

- name: Build toxchat/toktok-stack:latest-asan
run: |
docker build -t toxchat/toktok-stack:latest-asan -f tools/built/src/Dockerfile.asan .
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ http_archive(
urls = ["https://github.com/nlohmann/json/releases/download/v3.11.3/include.zip"],
)

# https://github.com/simdjson/simdjson/releases
new_github_archive(
name = "simdjson",
integrity = "sha256-hl/62dOtM7ARIHS6iJ7pNNtT1hPq/GOS7A0aDJ5bAFc=",
repo = "simdjson/simdjson",
version = "v3.11.6",
)

# https://github.com/libunwind/libunwind/releases
http_archive(
name = "libunwind",
Expand Down
9 changes: 9 additions & 0 deletions third_party/libsodium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
load("@rules_cc//cc:defs.bzl", "cc_test")

licenses(["notice"])

exports_files(
srcs = glob(["config/*.h"]) + ["version.h"],
visibility = ["@libsodium//:__pkg__"],
)

cc_test(
name = "libsodium_test",
size = "small",
srcs = ["libsodium_test.c"],
deps = ["@libsodium"],
)
40 changes: 40 additions & 0 deletions third_party/libsodium/libsodium_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <sodium.h>
#include <stdio.h>

static const char message[] = "hello world";
static const char expected_hash[crypto_generichash_BYTES] =
"\x25\x6c\x83\xb2\x97\x11\x4d\x20\x1b\x30\x17\x9f\x3f\x0e\xf0\xca"
"\xce\x97\x83\x62\x2d\xa5\x97\x43\x26\xb4\x36\x17\x8a\xee\xf6\x10";

// Check whether we can get a hash of a message.
int main(void)
{
if (sodium_init() < 0) {
return 1;
}

unsigned char hash[crypto_generichash_BYTES];
crypto_generichash(hash, sizeof hash, (const unsigned char*)message, sizeof message - 1, NULL, 0);

for (size_t i = 0; i < sizeof hash; i++) {
if (hash[i] != expected_hash[i]) {
fprintf(stderr, "expected: ");
for (size_t j = 0; j < sizeof expected_hash; j++) {
fprintf(stderr, "%02x", expected_hash[j]);
}
fputc('\n', stderr);
fprintf(stderr, "actual: ");
for (size_t j = 0; j < sizeof hash; j++) {
fprintf(stderr, "%02x", hash[j]);
}
fputs("\n ", stderr);
for (size_t j = 0; j < i; j++) {
fputs(" ", stderr);
}
fputs("^^\n", stderr);
return 1;
}
}

return 0;
}
9 changes: 9 additions & 0 deletions third_party/simdjson.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
name = "simdjson",
srcs = ["singleheader/simdjson.cpp"],
hdrs = ["singleheader/simdjson.h"],
includes = ["singleheader"],
visibility = ["//visibility:public"],
)
Loading