generated from bazel-contrib/rules-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from aherrmann/sys-header-deps
feat: Enable libc/libc++ linking to expose system headers
- Loading branch information
Showing
8 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
e2e/workspace/include-dependencies/zig-std-include/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
load("@bazel_skylib//rules:diff_test.bzl", "diff_test") | ||
load("@rules_zig//zig:defs.bzl", "zig_binary", "zig_library", "zig_test") | ||
|
||
zig_binary( | ||
name = "binary", | ||
cdeps = ["@rules_zig//zig/lib:libc"], | ||
main = "main.zig", | ||
) | ||
|
||
zig_library( | ||
name = "library", | ||
cdeps = ["@rules_zig//zig/lib:libc"], | ||
main = "main.zig", | ||
) | ||
|
||
zig_test( | ||
name = "test", | ||
size = "small", | ||
cdeps = ["@rules_zig//zig/lib:libc"], | ||
main = "main.zig", | ||
) | ||
|
||
build_test( | ||
name = "build", | ||
size = "small", | ||
targets = [ | ||
":binary", | ||
":library", | ||
":test", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "output", | ||
outs = ["output.actual"], | ||
cmd = "$(execpath :binary) > $(OUTS)", | ||
tools = [":binary"], | ||
) | ||
|
||
diff_test( | ||
name = "output_test", | ||
size = "small", | ||
file1 = ":output.expected", | ||
file2 = ":output.actual", | ||
) |
16 changes: 16 additions & 0 deletions
16
e2e/workspace/include-dependencies/zig-std-include/main.zig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const std = @import("std"); | ||
const c = @cImport({ | ||
@cInclude("math.h"); | ||
}); | ||
|
||
pub fn main() !void { | ||
const one = c.ceil(0.5); | ||
const two = c.ceil(1.5); | ||
try std.io.getStdOut().writer().print("{d}\n", .{one + two}); | ||
} | ||
|
||
test "One plus two equals three" { | ||
const one = c.ceil(0.5); | ||
const two = c.ceil(1.5); | ||
try std.testing.expectEqual(@as(f64, 3), one + two); | ||
} |
1 change: 1 addition & 0 deletions
1
e2e/workspace/include-dependencies/zig-std-include/output.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Helper targets to enable libc or libc++ linking. | ||
The Zig compiler ships with various versions of libc and libc++. However, it | ||
does not link against these libraries by default, and accordingly does not | ||
expose standard library headers for C imports by default. To enable the import | ||
of C standard library headers the compiler must be instructed to link against | ||
libc or libc++ as appropriate. | ||
The targets provided in this package can be used to accomplish this. Simply add | ||
them to the `cdeps` attribute of your Zig target to enable libc or libc++ | ||
linking. E.g. | ||
``` | ||
zig_binary( | ||
name = "binary", | ||
main = "main.zig", | ||
cdeps = ["@rules_zig//zig/lib:libc"], | ||
) | ||
``` | ||
""" | ||
|
||
cc_library( | ||
name = "libc", | ||
linkopts = ["-lc"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "libc++", | ||
linkopts = ["-lc++"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# Execute `bazel run //util:update_filegroups` to update this target. | ||
filegroup( | ||
name = "all_files", | ||
srcs = [":BUILD.bazel"], | ||
visibility = ["//zig:__pkg__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters