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

Fix examples/no-prelude/cpp #13

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions examples/no_prelude/cpp/.buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ name=BUILD

[repositories]
root = .
prelude = prelude
buck = no
fbcode = no
fbsource = no
ovr_config = no
toolchains = no
7 changes: 7 additions & 0 deletions examples/no_prelude/cpp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("//:toolchain.bzl", "cpp_local_toolchain")

cpp_local_toolchain(
name = "clang",
command = "clang++",
visibility = ["PUBLIC"],
)
8 changes: 1 addition & 7 deletions examples/no_prelude/cpp/hello-world/BUILD
Original file line number Diff line number Diff line change
@@ -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 = [],
)
1 change: 1 addition & 0 deletions examples/no_prelude/cpp/library/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ cpp_library(
srcs = glob(["src/**/*.cpp"]),
headers = glob(["src/**/*.hpp"]),
visibility = ["PUBLIC"],
toolchain = "//:clang",
deps = [],
)
1 change: 1 addition & 0 deletions examples/no_prelude/cpp/prelude
29 changes: 15 additions & 14 deletions examples/no_prelude/cpp/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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(),
},
)
6 changes: 3 additions & 3 deletions examples/no_prelude/cpp/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
)