Skip to content

Commit a905ed1

Browse files
Rust examples (#477)
As discussed with Alex Eagle on Slack recently, this PR contributes multiple Rust examples that cover roughly the top ten use cases. All examples use the new Bazelmod format. The format follows loosely the great C++ tutorial. If there is anything that needs adjustment, please let me know. Formalities: * I've signed the Google CLA * I've signed all commits --------- Signed-off-by: Marvin Hansen <[email protected]> Co-authored-by: Xùdōng Yáng <[email protected]>
1 parent 4d9f5e6 commit a905ed1

File tree

125 files changed

+132374
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+132374
-37
lines changed

.bazelci/presubmit.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
imports:
22
- android.yml
3+
- bzlmod.yml
34
- configurations.yml
4-
- misc.yml
55
- frontend.yml
6+
- misc.yml
67
- rules.yml
7-
- tutorials.yml
8-
- bzlmod.yml
8+
- tutorial-cpp.yml
9+
- tutorial-java.yml
10+
- tutorial-rust.yml

.bazelci/tutorials.yml renamed to .bazelci/tutorial-cpp.yml

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,52 @@ tasks:
55
platform: ubuntu1804
66
working_directory: ../cpp-tutorial/stage1
77
build_targets:
8-
- "..."
8+
- "..."
99
cpp-stage1-macos:
1010
name: "C++ Stage 1"
1111
platform: macos
1212
working_directory: ../cpp-tutorial/stage1
1313
build_targets:
14-
- "..."
14+
- "..."
1515
cpp-stage1-windows:
1616
name: "C++ Stage 1"
1717
platform: windows
1818
working_directory: ../cpp-tutorial/stage1
1919
build_targets:
20-
- "..."
20+
- "..."
2121
cpp-stage2-linux:
2222
name: "C++ Stage 2"
2323
platform: ubuntu1804
2424
working_directory: ../cpp-tutorial/stage2
2525
build_targets:
26-
- "..."
26+
- "..."
2727
cpp-stage2-macos:
2828
name: "C++ Stage 2"
2929
platform: macos
3030
working_directory: ../cpp-tutorial/stage2
3131
build_targets:
32-
- "..."
32+
- "..."
3333
cpp-stage2-windows:
3434
name: "C++ Stage 2"
3535
platform: windows
3636
working_directory: ../cpp-tutorial/stage2
3737
build_targets:
38-
- "..."
38+
- "..."
3939
cpp-stage3-linux:
4040
name: "C++ Stage 3"
4141
platform: ubuntu1804
4242
working_directory: ../cpp-tutorial/stage3
4343
build_targets:
44-
- "..."
44+
- "..."
4545
cpp-stage3-macos:
4646
name: "C++ Stage 3"
4747
platform: macos
4848
working_directory: ../cpp-tutorial/stage3
4949
build_targets:
50-
- "..."
50+
- "..."
5151
cpp-stage3-windows:
5252
name: "C++ Stage 3"
5353
platform: windows
5454
working_directory: ../cpp-tutorial/stage3
5555
build_targets:
56-
- "..."
57-
java-tutorial-linux:
58-
name: "Java Tutorial"
59-
platform: ubuntu1804
60-
working_directory: ../java-tutorial
61-
build_targets:
62-
- "//:ProjectRunner"
63-
java-tutorial-macos:
64-
name: "Java Tutorial"
65-
platform: macos
66-
working_directory: ../java-tutorial
67-
build_targets:
68-
- "//:ProjectRunner"
69-
java-tutorial-windows:
70-
name: "Java Tutorial"
71-
platform: windows
72-
working_directory: ../java-tutorial
73-
build_targets:
74-
- "//:ProjectRunner"
75-
query-quickstart:
76-
name: "Query Quickstart"
77-
platform: macos
78-
working_directory: ../query-quickstart
79-
build_targets:
80-
- "//:runner"
56+
- "..."

.bazelci/tutorial-java.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Getting started tutorials
2+
tasks:
3+
java-tutorial-linux:
4+
name: "Java Tutorial"
5+
platform: ubuntu1804
6+
working_directory: ../java-tutorial
7+
build_targets:
8+
- "//:ProjectRunner"
9+
java-tutorial-macos:
10+
name: "Java Tutorial"
11+
platform: macos
12+
working_directory: ../java-tutorial
13+
build_targets:
14+
- "//:ProjectRunner"
15+
java-tutorial-windows:
16+
name: "Java Tutorial"
17+
platform: windows
18+
working_directory: ../java-tutorial
19+
build_targets:
20+
- "//:ProjectRunner"
21+
22+
query-quickstart:
23+
name: "Query Quickstart"
24+
platform: macos
25+
working_directory: ../query-quickstart
26+
build_targets:
27+
- "//:runner"

.bazelci/tutorial-rust.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Getting started tutorials
2+
tasks:
3+
rust-01-hello-world-linux:
4+
name: "Rust Hello World"
5+
platform: ubuntu1804
6+
working_directory: ../rust-examples/01-hello-world
7+
build_targets:
8+
- "//..."
9+
rust-02-hello-cross-linux:
10+
name: "Rust Cross Compilation"
11+
platform: ubuntu1804
12+
working_directory: ../rust-examples/02-hello-cross
13+
build_targets:
14+
- "//:all"
15+
rust-02-hello-cross-mac:
16+
name: "Rust Cross Compilation"
17+
platform: macos
18+
working_directory: ../rust-examples/02-hello-cross
19+
build_targets:
20+
- "//:all"
21+
rust-03-comp-opt-linux:
22+
name: "Rust Compiler Optimization"
23+
platform: ubuntu1804
24+
working_directory: ../rust-examples/03-comp-opt
25+
build_targets:
26+
- "//..."
27+
rust-04-ffi-linux:
28+
name: "Rust FFI"
29+
platform: ubuntu1804
30+
working_directory: ../rust-examples/04-ffi
31+
build_targets:
32+
- "//..."
33+
rust-05-deps-cargo-linux:
34+
name: "Rust Cargo Deps"
35+
platform: ubuntu1804
36+
working_directory: ../rust-examples/05-deps-cargo
37+
build_targets:
38+
- "//..."
39+
rust-06-deps-direct-linux:
40+
name: "Rust Direct Deps"
41+
platform: ubuntu1804
42+
working_directory: ../rust-examples/06-deps-direct
43+
build_targets:
44+
- "//..."
45+
rust-07-deps-vendor-linux:
46+
name: "Rust Vendored Deps"
47+
platform: ubuntu1804
48+
working_directory: ../rust-examples/07-deps-vendor
49+
build_targets:
50+
- "//..."
51+
rust-08-grpc-client-server-linux:
52+
name: "Rust grpc"
53+
platform: ubuntu1804
54+
working_directory: ../rust-examples/08-grpc-client-server
55+
build_targets:
56+
- "//:all"
57+
rust-08-grpc-client-server-macos:
58+
name: "Rust grpc"
59+
platform: macos
60+
working_directory: ../rust-examples/08-grpc-client-server
61+
build_targets:
62+
- "//:all"
63+
rust-09-oci-container-linux:
64+
name: "Rust OCI"
65+
platform: ubuntu1804
66+
working_directory: ../rust-examples/09-oci-container
67+
build_targets:
68+
- "//..."
69+
- "//tokio_oci:image"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ bazel-*
99
target/
1010
# Xcode
1111
*.xcodeproj
12-
node_modules
12+
node_modules

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Note that tutorials for other languages may be found under other repositories:
3737

3838
* [Using Java with Maven](/java-maven)
3939

40+
### Rust
41+
42+
* [Building Rust](/rust-examples)
43+
4044
### Frontend
4145

4246
* [Next.js](/frontend/next.js)

rust-examples/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.2.1

rust-examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*/bazel-*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.bazelversion
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_rust//rust:defs.bzl", "rust_binary")
2+
3+
rust_binary(
4+
name = "bin",
5+
srcs = ["src/main.rs"],
6+
visibility = ["//visibility:public"],
7+
deps = [],
8+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module(
2+
name = "hello_world",
3+
version = "0.0.0",
4+
)
5+
6+
# https://github.com/bazelbuild/rules_rust/releases
7+
bazel_dep(name = "rules_rust", version = "0.47.1")
8+
9+
# Rust toolchain
10+
RUST_EDITION = "2021"
11+
12+
RUST_VERSION = "1.79.0"
13+
14+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
15+
rust.toolchain(
16+
edition = RUST_EDITION,
17+
versions = [RUST_VERSION],
18+
)
19+
use_repo(rust, "rust_toolchains")
20+
21+
register_toolchains("@rust_toolchains//:all")

0 commit comments

Comments
 (0)