Skip to content

Commit

Permalink
Add C example and file extension. (#349)
Browse files Browse the repository at this point in the history
* Add C example and file extension.

* First class support for C formatting.

* Update starlark docs.
  • Loading branch information
agoessling authored Aug 5, 2024
1 parent 5d056cb commit 7ef5063
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/format.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ cc_binary(
srcs = ["hello.cpp"],
)

cc_binary(
name = "hello_c",
srcs = ["hello.c"],
)

kt_jvm_library(
name = "hello_kt",
srcs = ["hello.kt"],
Expand Down
23 changes: 23 additions & 0 deletions example/src/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// deliberately bad code to trigger clang-tidy warning
int string_to_int(const char *num) { return atoi(num); }

// deliberately insecure code to trigger clang-tidy warning
void ls() { system("ls"); }

static int compare(int x, int y) {
if (x < y)
;
{ x++; }
return x;
}

int main() {
printf("Hello, world!\n");
compare(3, 4);
char *a = NULL;
char *b = 0;
}
1 change: 1 addition & 0 deletions example/tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ java_binary(

format_multirun(
name = "format",
c = "@llvm_toolchain_llvm//:bin/clang-format",
cc = "@llvm_toolchain_llvm//:bin/clang-format",
css = ":prettier",
cuda = "@llvm_toolchain_llvm//:bin/clang-format",
Expand Down
1 change: 1 addition & 0 deletions format/private/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function ls-files {
# https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml
# using the ./mirror_linguist_languages.sh tool to transform to Bash code
case "$language" in
'C') patterns=('*.c' '*.cats' '*.h' '*.idc') ;;
'C++') patterns=('*.cpp' '*.c++' '*.cc' '*.cp' '*.cppm' '*.cxx' '*.h' '*.h++' '*.hh' '*.hpp' '*.hxx' '*.inc' '*.inl' '*.ino' '*.ipp' '*.ixx' '*.re' '*.tcc' '*.tpp' '*.txx') ;;
'Cuda') patterns=('*.cu' '*.cuh') ;;
'CSS') patterns=('*.css') ;;
Expand Down
1 change: 1 addition & 0 deletions format/private/formatter_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TOOLS = {
"SQL": "prettier",
"Shell": "shfmt",
"Protocol Buffer": "buf",
"C": "clang-format",
"C++": "clang-format",
"Cuda": "clang-format",
"YAML": "yamlfmt",
Expand Down

0 comments on commit 7ef5063

Please sign in to comment.