Skip to content

Commit 39d49d8

Browse files
authored
Show getrandom and chrono/time usage in examples. (#51)
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
1 parent b8921ba commit 39d49d8

File tree

9 files changed

+305
-6
lines changed

9 files changed

+305
-6
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ log = "0.4"
1717
wee_alloc = { version = "0.4", optional = true }
1818

1919
[dev-dependencies]
20+
cfg-if = "1.0"
2021
chrono = "0.4"
2122

23+
[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies]
24+
getrandom = "0.2"
25+
2226
[profile.release]
2327
lto = true
2428
opt-level = 3

bazel/cargo/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ licenses([
1212
])
1313

1414
# Aliased targets
15+
alias(
16+
name = "cfg_if",
17+
actual = "@raze__cfg_if__1_0_0//:cfg_if",
18+
tags = [
19+
"cargo-raze",
20+
"manual",
21+
],
22+
)
23+
1524
alias(
1625
name = "chrono",
1726
actual = "@raze__chrono__0_4_19//:chrono",
@@ -21,6 +30,15 @@ alias(
2130
],
2231
)
2332

33+
alias(
34+
name = "getrandom",
35+
actual = "@raze__getrandom__0_2_0//:getrandom",
36+
tags = [
37+
"cargo-raze",
38+
"manual",
39+
],
40+
)
41+
2442
alias(
2543
name = "hashbrown",
2644
actual = "@raze__hashbrown__0_9_1//:hashbrown",

bazel/cargo/Cargo.lock

Lines changed: 28 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/cargo/crates.bzl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ def raze_fetch_remote_crates():
4141
build_file = Label("//bazel/cargo/remote:BUILD.cfg-if-0.1.10.bazel"),
4242
)
4343

44+
maybe(
45+
http_archive,
46+
name = "raze__cfg_if__1_0_0",
47+
url = "https://crates.io/api/v1/crates/cfg-if/1.0.0/download",
48+
type = "tar.gz",
49+
sha256 = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd",
50+
strip_prefix = "cfg-if-1.0.0",
51+
build_file = Label("//bazel/cargo/remote:BUILD.cfg-if-1.0.0.bazel"),
52+
)
53+
4454
maybe(
4555
http_archive,
4656
name = "raze__chrono__0_4_19",
@@ -51,6 +61,16 @@ def raze_fetch_remote_crates():
5161
build_file = Label("//bazel/cargo/remote:BUILD.chrono-0.4.19.bazel"),
5262
)
5363

64+
maybe(
65+
http_archive,
66+
name = "raze__getrandom__0_2_0",
67+
url = "https://crates.io/api/v1/crates/getrandom/0.2.0/download",
68+
type = "tar.gz",
69+
sha256 = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4",
70+
strip_prefix = "getrandom-0.2.0",
71+
build_file = Label("//bazel/cargo/remote:BUILD.getrandom-0.2.0.bazel"),
72+
)
73+
5474
maybe(
5575
http_archive,
5676
name = "raze__hashbrown__0_9_1",
@@ -121,6 +141,16 @@ def raze_fetch_remote_crates():
121141
build_file = Label("//bazel/cargo/remote:BUILD.wasi-0.10.0+wasi-snapshot-preview1.bazel"),
122142
)
123143

144+
maybe(
145+
http_archive,
146+
name = "raze__wasi__0_9_0_wasi_snapshot_preview1",
147+
url = "https://crates.io/api/v1/crates/wasi/0.9.0+wasi-snapshot-preview1/download",
148+
type = "tar.gz",
149+
sha256 = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519",
150+
strip_prefix = "wasi-0.9.0+wasi-snapshot-preview1",
151+
build_file = Label("//bazel/cargo/remote:BUILD.wasi-0.9.0+wasi-snapshot-preview1.bazel"),
152+
)
153+
124154
maybe(
125155
http_archive,
126156
name = "raze__winapi__0_3_9",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
@generated
3+
cargo-raze crate build file.
4+
5+
DO NOT EDIT! Replaced on runs of cargo-raze
6+
"""
7+
8+
# buildifier: disable=load
9+
load(
10+
"@io_bazel_rules_rust//rust:rust.bzl",
11+
"rust_binary",
12+
"rust_library",
13+
"rust_test",
14+
)
15+
16+
# buildifier: disable=load
17+
load("@bazel_skylib//lib:selects.bzl", "selects")
18+
19+
package(default_visibility = [
20+
# Public for visibility by "@raze__crate__version//" targets.
21+
#
22+
# Prefer access through "//bazel/cargo", which limits external
23+
# visibility to explicit Cargo.toml dependencies.
24+
"//visibility:public",
25+
])
26+
27+
licenses([
28+
"notice", # MIT from expression "MIT OR Apache-2.0"
29+
])
30+
31+
# Generated Targets
32+
33+
rust_library(
34+
name = "cfg_if",
35+
srcs = glob(["**/*.rs"]),
36+
crate_features = [
37+
],
38+
crate_root = "src/lib.rs",
39+
crate_type = "lib",
40+
edition = "2018",
41+
rustc_flags = [
42+
"--cap-lints=allow",
43+
],
44+
tags = [
45+
"cargo-raze",
46+
"manual",
47+
],
48+
version = "1.0.0",
49+
# buildifier: leave-alone
50+
deps = [
51+
],
52+
)
53+
54+
# Unsupported target "xcrate" with type "test" omitted
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
@generated
3+
cargo-raze crate build file.
4+
5+
DO NOT EDIT! Replaced on runs of cargo-raze
6+
"""
7+
8+
# buildifier: disable=load
9+
load(
10+
"@io_bazel_rules_rust//rust:rust.bzl",
11+
"rust_binary",
12+
"rust_library",
13+
"rust_test",
14+
)
15+
16+
# buildifier: disable=load
17+
load("@bazel_skylib//lib:selects.bzl", "selects")
18+
19+
package(default_visibility = [
20+
# Public for visibility by "@raze__crate__version//" targets.
21+
#
22+
# Prefer access through "//bazel/cargo", which limits external
23+
# visibility to explicit Cargo.toml dependencies.
24+
"//visibility:public",
25+
])
26+
27+
licenses([
28+
"notice", # MIT from expression "MIT OR Apache-2.0"
29+
])
30+
31+
# Generated Targets
32+
33+
# Unsupported target "mod" with type "bench" omitted
34+
35+
# Unsupported target "build-script-build" with type "custom-build" omitted
36+
37+
rust_library(
38+
name = "getrandom",
39+
srcs = glob(["**/*.rs"]),
40+
aliases = {
41+
},
42+
crate_features = [
43+
],
44+
crate_root = "src/lib.rs",
45+
crate_type = "lib",
46+
edition = "2018",
47+
rustc_flags = [
48+
"--cap-lints=allow",
49+
],
50+
tags = [
51+
"cargo-raze",
52+
"manual",
53+
],
54+
version = "0.2.0",
55+
# buildifier: leave-alone
56+
deps = [
57+
"@raze__cfg_if__0_1_10//:cfg_if",
58+
] + selects.with_or({
59+
# cfg(all(target_arch = "wasm32", target_os = "unknown", not(cargo_web)))
60+
(
61+
"@io_bazel_rules_rust//rust/platform:wasm32-unknown-unknown",
62+
): [
63+
],
64+
"//conditions:default": [],
65+
}) + selects.with_or({
66+
# cfg(target_os = "wasi")
67+
(
68+
"@io_bazel_rules_rust//rust/platform:wasm32-wasi",
69+
): [
70+
"@raze__wasi__0_9_0_wasi_snapshot_preview1//:wasi",
71+
],
72+
"//conditions:default": [],
73+
}) + selects.with_or({
74+
# cfg(unix)
75+
(
76+
"@io_bazel_rules_rust//rust/platform:aarch64-apple-ios",
77+
"@io_bazel_rules_rust//rust/platform:aarch64-linux-android",
78+
"@io_bazel_rules_rust//rust/platform:aarch64-unknown-linux-gnu",
79+
"@io_bazel_rules_rust//rust/platform:arm-unknown-linux-gnueabi",
80+
"@io_bazel_rules_rust//rust/platform:i686-apple-darwin",
81+
"@io_bazel_rules_rust//rust/platform:i686-linux-android",
82+
"@io_bazel_rules_rust//rust/platform:i686-unknown-freebsd",
83+
"@io_bazel_rules_rust//rust/platform:i686-unknown-linux-gnu",
84+
"@io_bazel_rules_rust//rust/platform:powerpc-unknown-linux-gnu",
85+
"@io_bazel_rules_rust//rust/platform:s390x-unknown-linux-gnu",
86+
"@io_bazel_rules_rust//rust/platform:x86_64-apple-darwin",
87+
"@io_bazel_rules_rust//rust/platform:x86_64-apple-ios",
88+
"@io_bazel_rules_rust//rust/platform:x86_64-linux-android",
89+
"@io_bazel_rules_rust//rust/platform:x86_64-unknown-freebsd",
90+
"@io_bazel_rules_rust//rust/platform:x86_64-unknown-linux-gnu",
91+
): [
92+
"@raze__libc__0_2_80//:libc",
93+
],
94+
"//conditions:default": [],
95+
}),
96+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
@generated
3+
cargo-raze crate build file.
4+
5+
DO NOT EDIT! Replaced on runs of cargo-raze
6+
"""
7+
8+
# buildifier: disable=load
9+
load(
10+
"@io_bazel_rules_rust//rust:rust.bzl",
11+
"rust_binary",
12+
"rust_library",
13+
"rust_test",
14+
)
15+
16+
# buildifier: disable=load
17+
load("@bazel_skylib//lib:selects.bzl", "selects")
18+
19+
package(default_visibility = [
20+
# Public for visibility by "@raze__crate__version//" targets.
21+
#
22+
# Prefer access through "//bazel/cargo", which limits external
23+
# visibility to explicit Cargo.toml dependencies.
24+
"//visibility:public",
25+
])
26+
27+
licenses([
28+
"notice", # Apache-2.0 from expression "Apache-2.0 OR (Apache-2.0 OR MIT)"
29+
])
30+
31+
# Generated Targets
32+
33+
rust_library(
34+
name = "wasi",
35+
srcs = glob(["**/*.rs"]),
36+
crate_features = [
37+
"default",
38+
"std",
39+
],
40+
crate_root = "src/lib.rs",
41+
crate_type = "lib",
42+
edition = "2018",
43+
rustc_flags = [
44+
"--cap-lints=allow",
45+
],
46+
tags = [
47+
"cargo-raze",
48+
"manual",
49+
],
50+
version = "0.9.0+wasi-snapshot-preview1",
51+
# buildifier: leave-alone
52+
deps = [
53+
],
54+
)

examples/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ rust_binary(
88
out_binary = True,
99
deps = [
1010
"//:proxy_wasm",
11+
"//bazel/cargo:cfg_if",
1112
"//bazel/cargo:chrono",
1213
"//bazel/cargo:log",
13-
],
14+
] + select({
15+
"@io_bazel_rules_rust//rust/platform:wasm32-unknown-unknown": [],
16+
"//conditions:default": ["//bazel/cargo:getrandom"],
17+
}),
1418
)
1519

1620
rust_binary(

0 commit comments

Comments
 (0)