From 0c00eae6e28c7942a1ae56fcddbc8efb3d38bef3 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 14 Jul 2022 13:56:31 +0100 Subject: [PATCH 1/8] Add examples folder with readme --- examples/.gitignore | 1 + examples/readme.md | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 examples/.gitignore create mode 100644 examples/readme.md diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000000000..d60c5d299b29c --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +buck-out diff --git a/examples/readme.md b/examples/readme.md new file mode 100644 index 0000000000000..062ce40d5f014 --- /dev/null +++ b/examples/readme.md @@ -0,0 +1,4 @@ +# buck2 examples + +In these folders are some examples on how to get buck2 working with +your favorite languages and tools. From 7e9e7b34a6b62fd4804bd2fb0c11e21063ec9ec8 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 14 Jul 2022 13:57:31 +0100 Subject: [PATCH 2/8] Add cpp hello-world example --- examples/cpp/.buckconfig | 5 +++++ examples/cpp/hello-world/TARGETS | 15 +++++++++++++++ examples/cpp/hello-world/src/func.cpp | 6 ++++++ examples/cpp/hello-world/src/func.hpp | 1 + examples/cpp/hello-world/src/main.cpp | 6 ++++++ examples/cpp/rules.bzl | 25 +++++++++++++++++++++++++ examples/cpp/toolchain.bzl | 14 ++++++++++++++ 7 files changed, 72 insertions(+) create mode 100644 examples/cpp/.buckconfig create mode 100644 examples/cpp/hello-world/TARGETS create mode 100644 examples/cpp/hello-world/src/func.cpp create mode 100644 examples/cpp/hello-world/src/func.hpp create mode 100644 examples/cpp/hello-world/src/main.cpp create mode 100644 examples/cpp/rules.bzl create mode 100644 examples/cpp/toolchain.bzl diff --git a/examples/cpp/.buckconfig b/examples/cpp/.buckconfig new file mode 100644 index 0000000000000..b22902ec20d41 --- /dev/null +++ b/examples/cpp/.buckconfig @@ -0,0 +1,5 @@ +[buildfile] +name=TARGETS + +[repositories] +root = . \ No newline at end of file diff --git a/examples/cpp/hello-world/TARGETS b/examples/cpp/hello-world/TARGETS new file mode 100644 index 0000000000000..e5b319e404858 --- /dev/null +++ b/examples/cpp/hello-world/TARGETS @@ -0,0 +1,15 @@ +load("//rules.bzl", "cpp_binary") +load("//toolchain.bzl", "cpp_local_toolchain") + +cpp_local_toolchain( + name = "clang", + command = "clang++" +) + +cpp_binary( + name = "main", + srcs = glob(["src/**/*.cpp"]), + headers = glob(["src/**/*.hpp"]), + deps = [], + toolchain = ":clang" +) \ No newline at end of file diff --git a/examples/cpp/hello-world/src/func.cpp b/examples/cpp/hello-world/src/func.cpp new file mode 100644 index 0000000000000..3bf97dfd5e8b8 --- /dev/null +++ b/examples/cpp/hello-world/src/func.cpp @@ -0,0 +1,6 @@ +#include + +void print_hello() +{ + std::cout << "hellp from cpp" << std::endl; +} \ No newline at end of file diff --git a/examples/cpp/hello-world/src/func.hpp b/examples/cpp/hello-world/src/func.hpp new file mode 100644 index 0000000000000..38a9c1a3a6492 --- /dev/null +++ b/examples/cpp/hello-world/src/func.hpp @@ -0,0 +1 @@ +void print_hello(); \ No newline at end of file diff --git a/examples/cpp/hello-world/src/main.cpp b/examples/cpp/hello-world/src/main.cpp new file mode 100644 index 0000000000000..fa2c7e6aecc1e --- /dev/null +++ b/examples/cpp/hello-world/src/main.cpp @@ -0,0 +1,6 @@ +#include "func.hpp" + +int main() +{ + print_hello(); +} \ No newline at end of file diff --git a/examples/cpp/rules.bzl b/examples/cpp/rules.bzl new file mode 100644 index 0000000000000..dfe8d23301bb2 --- /dev/null +++ b/examples/cpp/rules.bzl @@ -0,0 +1,25 @@ +load("//toolchain.bzl", "CxxCompilerInfo") + +def _cpp_binary_impl(ctx: "context") -> ["provider"]: + sources = ctx.attr.srcs + out = ctx.actions.declare_output("main") + + cmd = cmd_args([ctx.attr.toolchain[CxxCompilerInfo].compiler_path, "-o", out.as_output()] + sources) + + ctx.actions.run(cmd, category="compile") + + return [ + DefaultInfo(default_outputs = [out]), + RunInfo(args = cmd_args(out)) + ] + +cpp_binary = rule( + implementation = _cpp_binary_impl, + attrs = { + "srcs": attr.list(attr.source()), + "headers": attr.list(attr.source()), + "deps": attr.list(attr.dep()), + "toolchain": attr.dep(), + } +) + diff --git a/examples/cpp/toolchain.bzl b/examples/cpp/toolchain.bzl new file mode 100644 index 0000000000000..685efaea88949 --- /dev/null +++ b/examples/cpp/toolchain.bzl @@ -0,0 +1,14 @@ +CxxCompilerInfo = provider( + doc = "Information about how to invoke the cpp compiler.", + fields = ["compiler_path", "include_directories", "lib_directories"], +) + +def _cpp_local_toolchain_impl(ctx): + return [DefaultInfo(), CxxCompilerInfo(compiler_path = ctx.attr.command)] + +cpp_local_toolchain = rule( + implementation = _cpp_local_toolchain_impl, + attrs = { + "command": attr.string() + } +) From 4668130962746c7b3a94a17437523d474f83379f Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 14 Jul 2022 13:59:34 +0100 Subject: [PATCH 3/8] Add cpp library example --- examples/cpp/library/TARGETS | 10 ++++++++++ examples/cpp/library/src/library.cpp | 6 ++++++ examples/cpp/library/src/library.hpp | 1 + examples/cpp/rules.bzl | 21 +++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 examples/cpp/library/TARGETS create mode 100644 examples/cpp/library/src/library.cpp create mode 100644 examples/cpp/library/src/library.hpp diff --git a/examples/cpp/library/TARGETS b/examples/cpp/library/TARGETS new file mode 100644 index 0000000000000..985d9012f6e58 --- /dev/null +++ b/examples/cpp/library/TARGETS @@ -0,0 +1,10 @@ +load("//rules.bzl", "cpp_library") + +cpp_library( + name = "library", + visibility = ["//..."], + + srcs = glob(["src/**/*.cpp"]), + headers = glob(["src/**/*.hpp"]), + deps = [] +) diff --git a/examples/cpp/library/src/library.cpp b/examples/cpp/library/src/library.cpp new file mode 100644 index 0000000000000..e02d80b0f604c --- /dev/null +++ b/examples/cpp/library/src/library.cpp @@ -0,0 +1,6 @@ +#include + +void print_hello() +{ + std::cout << "hello from library" << std::endl; +} \ No newline at end of file diff --git a/examples/cpp/library/src/library.hpp b/examples/cpp/library/src/library.hpp new file mode 100644 index 0000000000000..38a9c1a3a6492 --- /dev/null +++ b/examples/cpp/library/src/library.hpp @@ -0,0 +1 @@ +void print_hello(); \ No newline at end of file diff --git a/examples/cpp/rules.bzl b/examples/cpp/rules.bzl index dfe8d23301bb2..874a502b969a1 100644 --- a/examples/cpp/rules.bzl +++ b/examples/cpp/rules.bzl @@ -1,5 +1,7 @@ load("//toolchain.bzl", "CxxCompilerInfo") +CxxLibraryInfo = provider(fields = ["headers", "objects", "include_folders"]) + def _cpp_binary_impl(ctx: "context") -> ["provider"]: sources = ctx.attr.srcs out = ctx.actions.declare_output("main") @@ -23,3 +25,22 @@ cpp_binary = rule( } ) +def _cpp_library_impl(ctx: "context") -> ["provider"]: + sources = ctx.attr.srcs + headers = ctx.attr.headers + out = ctx.actions.declare_output("lib.so") + + cmd = cmd_args(["clang++", "-shared", "-undefined", "dynamic_lookup", "-o", out.as_output()] + sources) + + ctx.actions.run(cmd, category="compile") + + return [DefaultInfo(default_outputs = [out]), CxxLibraryInfo(objects = [out], headers = headers)] + +cpp_library = rule( + implementation = _cpp_library_impl, + attrs = { + "srcs": attr.list(attr.source()), + "headers": attr.list(attr.source()), + "deps": attr.list(attr.dep()) + } +) \ No newline at end of file From 9ec81f2b2ddb955664772a6f92108975ad01c845 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 14 Jul 2022 14:17:37 +0100 Subject: [PATCH 4/8] Add go toolchain example --- examples/go/.buckconfig | 5 +++ examples/go/binary-toolchain/TARGETS | 17 +++++++++ examples/go/binary-toolchain/main.go | 7 ++++ examples/go/rules.bzl | 23 ++++++++++++ examples/go/toolchain.bzl | 56 ++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 examples/go/.buckconfig create mode 100644 examples/go/binary-toolchain/TARGETS create mode 100644 examples/go/binary-toolchain/main.go create mode 100644 examples/go/rules.bzl create mode 100644 examples/go/toolchain.bzl diff --git a/examples/go/.buckconfig b/examples/go/.buckconfig new file mode 100644 index 0000000000000..b22902ec20d41 --- /dev/null +++ b/examples/go/.buckconfig @@ -0,0 +1,5 @@ +[buildfile] +name=TARGETS + +[repositories] +root = . \ No newline at end of file diff --git a/examples/go/binary-toolchain/TARGETS b/examples/go/binary-toolchain/TARGETS new file mode 100644 index 0000000000000..33e888f08e26f --- /dev/null +++ b/examples/go/binary-toolchain/TARGETS @@ -0,0 +1,17 @@ +load("//rules.bzl", "go_binary") +load("//toolchain.bzl", "go_toolchain") + + +go_toolchain( + name = "go_linux", + version = "1.18.3", + platform = "linux-amd64", + sha1 = "3511fcb34e0162abdcdeea0ab532f0264943e3d8" +) + +go_binary( + name = "main", + srcs = glob(["*.go"]), + deps = [], + toolchain = ":go_linux" +) \ No newline at end of file diff --git a/examples/go/binary-toolchain/main.go b/examples/go/binary-toolchain/main.go new file mode 100644 index 0000000000000..f2ab1c904dbd6 --- /dev/null +++ b/examples/go/binary-toolchain/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("hello from go toolchain") +} diff --git a/examples/go/rules.bzl b/examples/go/rules.bzl new file mode 100644 index 0000000000000..8c7f9ab03d2bc --- /dev/null +++ b/examples/go/rules.bzl @@ -0,0 +1,23 @@ +load("//toolchain.bzl", "GoCompilerInfo") + +def _go_binary_impl(ctx: "context") -> ["provider"]: + sources = ctx.attr.srcs + out = ctx.actions.declare_output("main") + + cmd = cmd_args([ctx.attr.toolchain[GoCompilerInfo].compiler_path, "build", "-o", out.as_output()] + sources) + + ctx.actions.run(cmd, category="compile") + + return [ + DefaultInfo(default_outputs = [out]), + RunInfo(args = cmd_args(out)) + ] + +go_binary = rule( + implementation = _go_binary_impl, + attrs = { + "srcs": attr.list(attr.source()), + "deps": attr.list(attr.dep()), + "toolchain": attr.dep(), + } +) \ No newline at end of file diff --git a/examples/go/toolchain.bzl b/examples/go/toolchain.bzl new file mode 100644 index 0000000000000..80a04beb3c3c5 --- /dev/null +++ b/examples/go/toolchain.bzl @@ -0,0 +1,56 @@ +GoCompilerInfo = provider( + doc = "Information about how to invoke the go compiler.", + fields = ["compiler_path", "GOROOT"], +) + +def _go_toolchain_impl(ctx): + url = "https://go.dev/dl/go"+ctx.attr.version+"."+ctx.attr.platform+".tar.gz" + + download = http_archive_impl(ctx, url, ctx.attr.sha1) + + compiler_dst = ctx.actions.declare_output("compiler") + compiler_src = cmd_args(download[0].default_outputs[0], format="{}/go/bin/go") + ctx.actions.run(["ln","-srf", compiler_src, compiler_dst.as_output()], category="cp_compiler") + + # ctx.actions.symlink_file(compiler_dst, compiler_src) + + return download + [GoCompilerInfo(compiler_path = compiler_dst, GOROOT="")] + +go_toolchain = rule( + implementation = _go_toolchain_impl, + attrs = { + "version": attr.string(), + "platform": attr.string(), + "sha1": attr.string(), + }, +) + + + + +def http_archive_impl(ctx: "context", url, sha1) -> ["provider"]: + # Download archive. + archive = ctx.actions.declare_output("archive.tar.gz") + ctx.actions.download_file(archive.as_output(), url, sha1 = sha1, is_deferrable = True) + + # Unpack archive to output directory. + compress_flag = "-z" + + output = ctx.actions.declare_output(ctx.label.name) + script, hidden = ctx.actions.write( + "unpack.sh", + [ + cmd_args(output, format = "mkdir -p {}"), + cmd_args(output, format = "cd {}"), + cmd_args(["tar", compress_flag, "-x", "-f", archive], delimiter = " ").relative_to(output), + ], + is_executable = True, + allow_args = True, + ) + + print(dir(output), output.short_path, str(output)) + + ctx.actions.run(cmd_args(["/bin/sh", script]) + .hidden(hidden + [archive, output.as_output()]), category = "http_archive") + + return [DefaultInfo(default_outputs = [output])] From 0737b82ae2392f3f3de092295b80070f4cee0233 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 14 Jul 2022 14:11:27 +0100 Subject: [PATCH 5/8] Add basic rustc example --- examples/rust/.buckconfig | 5 +++++ examples/rust/rules.bzl | 17 +++++++++++++++++ examples/rust/rustc/TARGETS | 6 ++++++ examples/rust/rustc/main.rs | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 examples/rust/.buckconfig create mode 100644 examples/rust/rules.bzl create mode 100644 examples/rust/rustc/TARGETS create mode 100644 examples/rust/rustc/main.rs diff --git a/examples/rust/.buckconfig b/examples/rust/.buckconfig new file mode 100644 index 0000000000000..b22902ec20d41 --- /dev/null +++ b/examples/rust/.buckconfig @@ -0,0 +1,5 @@ +[buildfile] +name=TARGETS + +[repositories] +root = . \ No newline at end of file diff --git a/examples/rust/rules.bzl b/examples/rust/rules.bzl new file mode 100644 index 0000000000000..a5a140862a17c --- /dev/null +++ b/examples/rust/rules.bzl @@ -0,0 +1,17 @@ +def _rust_binary_impl(ctx): + file = ctx.attr.file + out = ctx.actions.declare_output("main") + + cmd = cmd_args(["rustc", "--crate-type=bin", file, "-o", out.as_output()]) + + ctx.actions.run(cmd, category="compile") + + return [DefaultInfo(default_outputs = [out]), RunInfo(args=cmd_args([out]))] + + +rust_binary = rule( + implementation = _rust_binary_impl, + attrs = { + "file": attr.source() + }, +) diff --git a/examples/rust/rustc/TARGETS b/examples/rust/rustc/TARGETS new file mode 100644 index 0000000000000..b8a7972b95f2a --- /dev/null +++ b/examples/rust/rustc/TARGETS @@ -0,0 +1,6 @@ +load("//rules.bzl", "rust_binary") + +rust_binary( + name = "main", + file = "./main.rs" +) diff --git a/examples/rust/rustc/main.rs b/examples/rust/rustc/main.rs new file mode 100644 index 0000000000000..d0bacf60ab268 --- /dev/null +++ b/examples/rust/rustc/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("hello from rustc"); +} From f62bf2bbf125c2f050a594fad18509e8a9d38de1 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Mon, 18 Jul 2022 10:48:30 +0100 Subject: [PATCH 6/8] Run buildifier --- examples/cpp/hello-world/TARGETS | 6 +++--- examples/cpp/library/TARGETS | 3 +-- examples/cpp/rules.bzl | 20 ++++++++++---------- examples/cpp/toolchain.bzl | 4 ++-- examples/go/binary-toolchain/TARGETS | 7 +++---- examples/go/rules.bzl | 12 ++++++------ examples/go/toolchain.bzl | 11 ++++------- examples/rust/rules.bzl | 7 +++---- examples/rust/rustc/TARGETS | 2 +- 9 files changed, 33 insertions(+), 39 deletions(-) diff --git a/examples/cpp/hello-world/TARGETS b/examples/cpp/hello-world/TARGETS index e5b319e404858..755189fd7da6b 100644 --- a/examples/cpp/hello-world/TARGETS +++ b/examples/cpp/hello-world/TARGETS @@ -3,7 +3,7 @@ load("//toolchain.bzl", "cpp_local_toolchain") cpp_local_toolchain( name = "clang", - command = "clang++" + command = "clang++", ) cpp_binary( @@ -11,5 +11,5 @@ cpp_binary( srcs = glob(["src/**/*.cpp"]), headers = glob(["src/**/*.hpp"]), deps = [], - toolchain = ":clang" -) \ No newline at end of file + toolchain = ":clang", +) diff --git a/examples/cpp/library/TARGETS b/examples/cpp/library/TARGETS index 985d9012f6e58..3b614111ee60f 100644 --- a/examples/cpp/library/TARGETS +++ b/examples/cpp/library/TARGETS @@ -3,8 +3,7 @@ load("//rules.bzl", "cpp_library") cpp_library( name = "library", visibility = ["//..."], - srcs = glob(["src/**/*.cpp"]), headers = glob(["src/**/*.hpp"]), - deps = [] + deps = [], ) diff --git a/examples/cpp/rules.bzl b/examples/cpp/rules.bzl index 874a502b969a1..a9f456ad7e3b5 100644 --- a/examples/cpp/rules.bzl +++ b/examples/cpp/rules.bzl @@ -8,11 +8,11 @@ def _cpp_binary_impl(ctx: "context") -> ["provider"]: cmd = cmd_args([ctx.attr.toolchain[CxxCompilerInfo].compiler_path, "-o", out.as_output()] + sources) - ctx.actions.run(cmd, category="compile") - + ctx.actions.run(cmd, category = "compile") + return [ - DefaultInfo(default_outputs = [out]), - RunInfo(args = cmd_args(out)) + DefaultInfo(default_outputs = [out]), + RunInfo(args = cmd_args(out)), ] cpp_binary = rule( @@ -22,7 +22,7 @@ cpp_binary = rule( "headers": attr.list(attr.source()), "deps": attr.list(attr.dep()), "toolchain": attr.dep(), - } + }, ) def _cpp_library_impl(ctx: "context") -> ["provider"]: @@ -32,8 +32,8 @@ def _cpp_library_impl(ctx: "context") -> ["provider"]: cmd = cmd_args(["clang++", "-shared", "-undefined", "dynamic_lookup", "-o", out.as_output()] + sources) - ctx.actions.run(cmd, category="compile") - + ctx.actions.run(cmd, category = "compile") + return [DefaultInfo(default_outputs = [out]), CxxLibraryInfo(objects = [out], headers = headers)] cpp_library = rule( @@ -41,6 +41,6 @@ cpp_library = rule( attrs = { "srcs": attr.list(attr.source()), "headers": attr.list(attr.source()), - "deps": attr.list(attr.dep()) - } -) \ No newline at end of file + "deps": attr.list(attr.dep()), + }, +) diff --git a/examples/cpp/toolchain.bzl b/examples/cpp/toolchain.bzl index 685efaea88949..7561d3f8b2f46 100644 --- a/examples/cpp/toolchain.bzl +++ b/examples/cpp/toolchain.bzl @@ -9,6 +9,6 @@ def _cpp_local_toolchain_impl(ctx): cpp_local_toolchain = rule( implementation = _cpp_local_toolchain_impl, attrs = { - "command": attr.string() - } + "command": attr.string(), + }, ) diff --git a/examples/go/binary-toolchain/TARGETS b/examples/go/binary-toolchain/TARGETS index 33e888f08e26f..d976968ed8885 100644 --- a/examples/go/binary-toolchain/TARGETS +++ b/examples/go/binary-toolchain/TARGETS @@ -1,17 +1,16 @@ load("//rules.bzl", "go_binary") load("//toolchain.bzl", "go_toolchain") - go_toolchain( name = "go_linux", version = "1.18.3", platform = "linux-amd64", - sha1 = "3511fcb34e0162abdcdeea0ab532f0264943e3d8" + sha1 = "3511fcb34e0162abdcdeea0ab532f0264943e3d8", ) go_binary( name = "main", srcs = glob(["*.go"]), deps = [], - toolchain = ":go_linux" -) \ No newline at end of file + toolchain = ":go_linux", +) diff --git a/examples/go/rules.bzl b/examples/go/rules.bzl index 8c7f9ab03d2bc..95ab3caf04639 100644 --- a/examples/go/rules.bzl +++ b/examples/go/rules.bzl @@ -6,11 +6,11 @@ def _go_binary_impl(ctx: "context") -> ["provider"]: cmd = cmd_args([ctx.attr.toolchain[GoCompilerInfo].compiler_path, "build", "-o", out.as_output()] + sources) - ctx.actions.run(cmd, category="compile") - + ctx.actions.run(cmd, category = "compile") + return [ - DefaultInfo(default_outputs = [out]), - RunInfo(args = cmd_args(out)) + DefaultInfo(default_outputs = [out]), + RunInfo(args = cmd_args(out)), ] go_binary = rule( @@ -19,5 +19,5 @@ go_binary = rule( "srcs": attr.list(attr.source()), "deps": attr.list(attr.dep()), "toolchain": attr.dep(), - } -) \ No newline at end of file + }, +) diff --git a/examples/go/toolchain.bzl b/examples/go/toolchain.bzl index 80a04beb3c3c5..916af00a7b0bc 100644 --- a/examples/go/toolchain.bzl +++ b/examples/go/toolchain.bzl @@ -4,17 +4,17 @@ GoCompilerInfo = provider( ) def _go_toolchain_impl(ctx): - url = "https://go.dev/dl/go"+ctx.attr.version+"."+ctx.attr.platform+".tar.gz" + url = "https://go.dev/dl/go" + ctx.attr.version + "." + ctx.attr.platform + ".tar.gz" download = http_archive_impl(ctx, url, ctx.attr.sha1) compiler_dst = ctx.actions.declare_output("compiler") - compiler_src = cmd_args(download[0].default_outputs[0], format="{}/go/bin/go") - ctx.actions.run(["ln","-srf", compiler_src, compiler_dst.as_output()], category="cp_compiler") + compiler_src = cmd_args(download[0].default_outputs[0], format = "{}/go/bin/go") + ctx.actions.run(["ln", "-srf", compiler_src, compiler_dst.as_output()], category = "cp_compiler") # ctx.actions.symlink_file(compiler_dst, compiler_src) - return download + [GoCompilerInfo(compiler_path = compiler_dst, GOROOT="")] + return download + [GoCompilerInfo(compiler_path = compiler_dst, GOROOT = "")] go_toolchain = rule( implementation = _go_toolchain_impl, @@ -25,9 +25,6 @@ go_toolchain = rule( }, ) - - - def http_archive_impl(ctx: "context", url, sha1) -> ["provider"]: # Download archive. archive = ctx.actions.declare_output("archive.tar.gz") diff --git a/examples/rust/rules.bzl b/examples/rust/rules.bzl index a5a140862a17c..1bda4f4e3c134 100644 --- a/examples/rust/rules.bzl +++ b/examples/rust/rules.bzl @@ -4,14 +4,13 @@ def _rust_binary_impl(ctx): cmd = cmd_args(["rustc", "--crate-type=bin", file, "-o", out.as_output()]) - ctx.actions.run(cmd, category="compile") - - return [DefaultInfo(default_outputs = [out]), RunInfo(args=cmd_args([out]))] + ctx.actions.run(cmd, category = "compile") + return [DefaultInfo(default_outputs = [out]), RunInfo(args = cmd_args([out]))] rust_binary = rule( implementation = _rust_binary_impl, attrs = { - "file": attr.source() + "file": attr.source(), }, ) diff --git a/examples/rust/rustc/TARGETS b/examples/rust/rustc/TARGETS index b8a7972b95f2a..7bccbed87c523 100644 --- a/examples/rust/rustc/TARGETS +++ b/examples/rust/rustc/TARGETS @@ -2,5 +2,5 @@ load("//rules.bzl", "rust_binary") rust_binary( name = "main", - file = "./main.rs" + file = "./main.rs", ) From 8eac6b73b54cea837efdbf6aad9e6f15b186812c Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 19 Jul 2022 17:31:34 +0100 Subject: [PATCH 7/8] Fix import linter issue --- examples/cpp/hello-world/TARGETS | 4 ++-- examples/cpp/library/TARGETS | 2 +- examples/go/binary-toolchain/TARGETS | 4 ++-- examples/rust/rustc/TARGETS | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/cpp/hello-world/TARGETS b/examples/cpp/hello-world/TARGETS index 755189fd7da6b..9790cc0b270c0 100644 --- a/examples/cpp/hello-world/TARGETS +++ b/examples/cpp/hello-world/TARGETS @@ -1,5 +1,5 @@ -load("//rules.bzl", "cpp_binary") -load("//toolchain.bzl", "cpp_local_toolchain") +load("//:rules.bzl", "cpp_binary") +load("//:toolchain.bzl", "cpp_local_toolchain") cpp_local_toolchain( name = "clang", diff --git a/examples/cpp/library/TARGETS b/examples/cpp/library/TARGETS index 3b614111ee60f..7d07f90e9bb92 100644 --- a/examples/cpp/library/TARGETS +++ b/examples/cpp/library/TARGETS @@ -1,4 +1,4 @@ -load("//rules.bzl", "cpp_library") +load("//:rules.bzl", "cpp_library") cpp_library( name = "library", diff --git a/examples/go/binary-toolchain/TARGETS b/examples/go/binary-toolchain/TARGETS index d976968ed8885..e9f1d93416d36 100644 --- a/examples/go/binary-toolchain/TARGETS +++ b/examples/go/binary-toolchain/TARGETS @@ -1,5 +1,5 @@ -load("//rules.bzl", "go_binary") -load("//toolchain.bzl", "go_toolchain") +load("//:rules.bzl", "go_binary") +load("//:toolchain.bzl", "go_toolchain") go_toolchain( name = "go_linux", diff --git a/examples/rust/rustc/TARGETS b/examples/rust/rustc/TARGETS index 7bccbed87c523..629692b97fe31 100644 --- a/examples/rust/rustc/TARGETS +++ b/examples/rust/rustc/TARGETS @@ -1,4 +1,4 @@ -load("//rules.bzl", "rust_binary") +load("//:rules.bzl", "rust_binary") rust_binary( name = "main", From 014c91cff3aa262a12511242f85d8a876f0781b5 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Tue, 19 Jul 2022 17:34:53 +0100 Subject: [PATCH 8/8] Fix newline liter issue --- examples/cpp/.buckconfig | 2 +- examples/cpp/hello-world/src/func.cpp | 2 +- examples/cpp/hello-world/src/func.hpp | 2 +- examples/cpp/hello-world/src/main.cpp | 2 +- examples/cpp/library/src/library.cpp | 2 +- examples/cpp/library/src/library.hpp | 2 +- examples/go/.buckconfig | 2 +- examples/rust/.buckconfig | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/cpp/.buckconfig b/examples/cpp/.buckconfig index b22902ec20d41..761b6ee921a42 100644 --- a/examples/cpp/.buckconfig +++ b/examples/cpp/.buckconfig @@ -2,4 +2,4 @@ name=TARGETS [repositories] -root = . \ No newline at end of file +root = . diff --git a/examples/cpp/hello-world/src/func.cpp b/examples/cpp/hello-world/src/func.cpp index 3bf97dfd5e8b8..7a09ee44b3ab2 100644 --- a/examples/cpp/hello-world/src/func.cpp +++ b/examples/cpp/hello-world/src/func.cpp @@ -3,4 +3,4 @@ void print_hello() { std::cout << "hellp from cpp" << std::endl; -} \ No newline at end of file +} diff --git a/examples/cpp/hello-world/src/func.hpp b/examples/cpp/hello-world/src/func.hpp index 38a9c1a3a6492..8c659df73a258 100644 --- a/examples/cpp/hello-world/src/func.hpp +++ b/examples/cpp/hello-world/src/func.hpp @@ -1 +1 @@ -void print_hello(); \ No newline at end of file +void print_hello(); diff --git a/examples/cpp/hello-world/src/main.cpp b/examples/cpp/hello-world/src/main.cpp index fa2c7e6aecc1e..c65daaf1f7d1d 100644 --- a/examples/cpp/hello-world/src/main.cpp +++ b/examples/cpp/hello-world/src/main.cpp @@ -3,4 +3,4 @@ int main() { print_hello(); -} \ No newline at end of file +} diff --git a/examples/cpp/library/src/library.cpp b/examples/cpp/library/src/library.cpp index e02d80b0f604c..8e097e4200568 100644 --- a/examples/cpp/library/src/library.cpp +++ b/examples/cpp/library/src/library.cpp @@ -3,4 +3,4 @@ void print_hello() { std::cout << "hello from library" << std::endl; -} \ No newline at end of file +} diff --git a/examples/cpp/library/src/library.hpp b/examples/cpp/library/src/library.hpp index 38a9c1a3a6492..8c659df73a258 100644 --- a/examples/cpp/library/src/library.hpp +++ b/examples/cpp/library/src/library.hpp @@ -1 +1 @@ -void print_hello(); \ No newline at end of file +void print_hello(); diff --git a/examples/go/.buckconfig b/examples/go/.buckconfig index b22902ec20d41..761b6ee921a42 100644 --- a/examples/go/.buckconfig +++ b/examples/go/.buckconfig @@ -2,4 +2,4 @@ name=TARGETS [repositories] -root = . \ No newline at end of file +root = . diff --git a/examples/rust/.buckconfig b/examples/rust/.buckconfig index b22902ec20d41..761b6ee921a42 100644 --- a/examples/rust/.buckconfig +++ b/examples/rust/.buckconfig @@ -2,4 +2,4 @@ name=TARGETS [repositories] -root = . \ No newline at end of file +root = .