Skip to content

Commit 5665a3a

Browse files
committed
Add basic example
1 parent b23c4a3 commit 5665a3a

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

devserver/BUILD

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
cc_binary(
1+
filegroup(
2+
name = "httplib",
3+
srcs = glob(["httplib/httplib.h"]),
4+
visibility = ["//visibility:public"]
5+
)
6+
7+
filegroup(
28
name = "main",
3-
srcs = [
4-
"main.cc",
5-
"httplib/httplib.h"
6-
],
7-
linkopts = ["-lpthread"],
9+
srcs = glob(["main.cc"]),
10+
visibility = ["//visibility:public"],
811
)

devserver/defs.bzl

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
def _impl(ctx):
2-
executable = ctx.actions.declare_file(ctx.attr.name)
3-
4-
args = ctx.actions.args()
5-
args.add("-o", executable)
6-
args.add_all(ctx.files.srcs)
7-
8-
ctx.actions.run(
9-
inputs = ctx.files.srcs,
10-
outputs = [executable],
11-
# This is for demo purposes. In a real Bazel rule you'd
12-
# want to use cc_common.
13-
executable = "/usr/bin/gcc",
14-
arguments = [args],
1+
def devserver(name, port):
2+
native.cc_binary(
3+
name = name,
4+
srcs = [
5+
Label("@rules_devserver//devserver:main"),
6+
Label("@rules_devserver//devserver:httplib")
7+
],
8+
linkopts = ["-lpthread"],
159
)
16-
17-
return [
18-
DefaultInfo(
19-
executable = executable,
20-
files = depset([executable]),
21-
),
22-
]
23-
24-
my_cc_binary = rule(
25-
implementation = _impl,
26-
attrs = {
27-
"srcs": attr.label_list(
28-
mandatory = True,
29-
allow_files = True,
30-
),
31-
},
32-
executable = True,
33-
)

examples/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
load("//devserver:defs.bzl", "devserver")
2+
3+
devserver(
4+
name = "serve",
5+
port = 8080,
6+
)

0 commit comments

Comments
 (0)