diff --git a/examples/no_prelude/cpp/.buckconfig b/examples/no_prelude/cpp/.buckconfig index 0427950719b2..5c86795cfe94 100644 --- a/examples/no_prelude/cpp/.buckconfig +++ b/examples/no_prelude/cpp/.buckconfig @@ -3,3 +3,9 @@ name=BUILD [repositories] root = . +prelude = prelude +buck = no +fbcode = no +fbsource = no +ovr_config = no +toolchains = no diff --git a/examples/no_prelude/cpp/BUILD b/examples/no_prelude/cpp/BUILD new file mode 100644 index 000000000000..00f73397588a --- /dev/null +++ b/examples/no_prelude/cpp/BUILD @@ -0,0 +1,7 @@ +load("//:toolchain.bzl", "cpp_local_toolchain") + +cpp_local_toolchain( + name = "clang", + command = "clang++", + visibility = ["PUBLIC"], +) diff --git a/examples/no_prelude/cpp/hello-world/BUILD b/examples/no_prelude/cpp/hello-world/BUILD index 99c296a9413b..0d86c7dcddfd 100644 --- a/examples/no_prelude/cpp/hello-world/BUILD +++ b/examples/no_prelude/cpp/hello-world/BUILD @@ -1,15 +1,9 @@ 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"]), - toolchain = ":clang", + toolchain = "//:clang", deps = [], ) diff --git a/examples/no_prelude/cpp/library/BUILD b/examples/no_prelude/cpp/library/BUILD index e809793a0762..54dda5fafcb3 100644 --- a/examples/no_prelude/cpp/library/BUILD +++ b/examples/no_prelude/cpp/library/BUILD @@ -5,5 +5,6 @@ cpp_library( srcs = glob(["src/**/*.cpp"]), headers = glob(["src/**/*.hpp"]), visibility = ["PUBLIC"], + toolchain = "//:clang", deps = [], ) diff --git a/examples/no_prelude/cpp/prelude b/examples/no_prelude/cpp/prelude new file mode 120000 index 000000000000..0d1a9721f941 --- /dev/null +++ b/examples/no_prelude/cpp/prelude @@ -0,0 +1 @@ +../../../prelude \ No newline at end of file diff --git a/examples/no_prelude/cpp/rules.bzl b/examples/no_prelude/cpp/rules.bzl index 793c41e407d5..fe2c57876ae0 100644 --- a/examples/no_prelude/cpp/rules.bzl +++ b/examples/no_prelude/cpp/rules.bzl @@ -3,10 +3,10 @@ load("//toolchain.bzl", "CxxCompilerInfo") CxxLibraryInfo = provider(fields = ["headers", "objects", "include_folders"]) def _cpp_binary_impl(ctx: "context") -> ["provider"]: - sources = ctx.attr.srcs + sources = ctx.attrs.srcs out = ctx.actions.declare_output("main") - cmd = cmd_args([ctx.attr.toolchain[CxxCompilerInfo].compiler_path, "-o", out.as_output()] + sources) + cmd = cmd_args([ctx.attrs.toolchain[CxxCompilerInfo].compiler_path, "-o", out.as_output()] + sources) ctx.actions.run(cmd, category = "compile") @@ -16,31 +16,32 @@ def _cpp_binary_impl(ctx: "context") -> ["provider"]: ] cpp_binary = rule( - implementation = _cpp_binary_impl, + impl = _cpp_binary_impl, attrs = { - "deps": attr.list(attr.dep()), - "headers": attr.list(attr.source()), - "srcs": attr.list(attr.source()), - "toolchain": attr.toolchain_dep(), + "deps": attrs.list(attrs.dep()), + "headers": attrs.list(attrs.source()), + "srcs": attrs.list(attrs.source()), + "toolchain": attrs.toolchain_dep(), }, ) def _cpp_library_impl(ctx: "context") -> ["provider"]: - sources = ctx.attr.srcs - headers = ctx.attr.headers + sources = ctx.attrs.srcs + headers = ctx.attrs.headers out = ctx.actions.declare_output("lib.so") - cmd = cmd_args(["clang++", "-shared", "-undefined", "dynamic_lookup", "-o", out.as_output()] + sources) + cmd = cmd_args([ctx.attrs.toolchain[CxxCompilerInfo].compiler_path, "-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, + impl = _cpp_library_impl, attrs = { - "deps": attr.list(attr.dep()), - "headers": attr.list(attr.source()), - "srcs": attr.list(attr.source()), + "deps": attrs.list(attrs.dep()), + "headers": attrs.list(attrs.source()), + "srcs": attrs.list(attrs.source()), + "toolchain": attrs.toolchain_dep(), }, ) diff --git a/examples/no_prelude/cpp/toolchain.bzl b/examples/no_prelude/cpp/toolchain.bzl index 0bbf8ab69361..bf568e62148d 100644 --- a/examples/no_prelude/cpp/toolchain.bzl +++ b/examples/no_prelude/cpp/toolchain.bzl @@ -4,12 +4,12 @@ CxxCompilerInfo = provider( ) def _cpp_local_toolchain_impl(ctx): - return [DefaultInfo(), CxxCompilerInfo(compiler_path = ctx.attr.command)] + return [DefaultInfo(), CxxCompilerInfo(compiler_path = ctx.attrs.command)] cpp_local_toolchain = rule( - implementation = _cpp_local_toolchain_impl, + impl = _cpp_local_toolchain_impl, is_toolchain_rule = True, attrs = { - "command": attr.string(), + "command": attrs.string(), }, )