Skip to content

Commit

Permalink
Rust examples (#477)
Browse files Browse the repository at this point in the history
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 <marvin.hansen@gmail.com>
Co-authored-by: Xùdōng Yáng <wyverald@gmail.com>
  • Loading branch information
marvin-hansen and Wyverald authored Jul 23, 2024
1 parent 4d9f5e6 commit a905ed1
Show file tree
Hide file tree
Showing 125 changed files with 132,374 additions and 37 deletions.
8 changes: 5 additions & 3 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
imports:
- android.yml
- bzlmod.yml
- configurations.yml
- misc.yml
- frontend.yml
- misc.yml
- rules.yml
- tutorials.yml
- bzlmod.yml
- tutorial-cpp.yml
- tutorial-java.yml
- tutorial-rust.yml
42 changes: 9 additions & 33 deletions .bazelci/tutorials.yml → .bazelci/tutorial-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,52 @@ tasks:
platform: ubuntu1804
working_directory: ../cpp-tutorial/stage1
build_targets:
- "..."
- "..."
cpp-stage1-macos:
name: "C++ Stage 1"
platform: macos
working_directory: ../cpp-tutorial/stage1
build_targets:
- "..."
- "..."
cpp-stage1-windows:
name: "C++ Stage 1"
platform: windows
working_directory: ../cpp-tutorial/stage1
build_targets:
- "..."
- "..."
cpp-stage2-linux:
name: "C++ Stage 2"
platform: ubuntu1804
working_directory: ../cpp-tutorial/stage2
build_targets:
- "..."
- "..."
cpp-stage2-macos:
name: "C++ Stage 2"
platform: macos
working_directory: ../cpp-tutorial/stage2
build_targets:
- "..."
- "..."
cpp-stage2-windows:
name: "C++ Stage 2"
platform: windows
working_directory: ../cpp-tutorial/stage2
build_targets:
- "..."
- "..."
cpp-stage3-linux:
name: "C++ Stage 3"
platform: ubuntu1804
working_directory: ../cpp-tutorial/stage3
build_targets:
- "..."
- "..."
cpp-stage3-macos:
name: "C++ Stage 3"
platform: macos
working_directory: ../cpp-tutorial/stage3
build_targets:
- "..."
- "..."
cpp-stage3-windows:
name: "C++ Stage 3"
platform: windows
working_directory: ../cpp-tutorial/stage3
build_targets:
- "..."
java-tutorial-linux:
name: "Java Tutorial"
platform: ubuntu1804
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"
java-tutorial-macos:
name: "Java Tutorial"
platform: macos
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"
java-tutorial-windows:
name: "Java Tutorial"
platform: windows
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"
query-quickstart:
name: "Query Quickstart"
platform: macos
working_directory: ../query-quickstart
build_targets:
- "//:runner"
- "..."
27 changes: 27 additions & 0 deletions .bazelci/tutorial-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Getting started tutorials
tasks:
java-tutorial-linux:
name: "Java Tutorial"
platform: ubuntu1804
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"
java-tutorial-macos:
name: "Java Tutorial"
platform: macos
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"
java-tutorial-windows:
name: "Java Tutorial"
platform: windows
working_directory: ../java-tutorial
build_targets:
- "//:ProjectRunner"

query-quickstart:
name: "Query Quickstart"
platform: macos
working_directory: ../query-quickstart
build_targets:
- "//:runner"
69 changes: 69 additions & 0 deletions .bazelci/tutorial-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Getting started tutorials
tasks:
rust-01-hello-world-linux:
name: "Rust Hello World"
platform: ubuntu1804
working_directory: ../rust-examples/01-hello-world
build_targets:
- "//..."
rust-02-hello-cross-linux:
name: "Rust Cross Compilation"
platform: ubuntu1804
working_directory: ../rust-examples/02-hello-cross
build_targets:
- "//:all"
rust-02-hello-cross-mac:
name: "Rust Cross Compilation"
platform: macos
working_directory: ../rust-examples/02-hello-cross
build_targets:
- "//:all"
rust-03-comp-opt-linux:
name: "Rust Compiler Optimization"
platform: ubuntu1804
working_directory: ../rust-examples/03-comp-opt
build_targets:
- "//..."
rust-04-ffi-linux:
name: "Rust FFI"
platform: ubuntu1804
working_directory: ../rust-examples/04-ffi
build_targets:
- "//..."
rust-05-deps-cargo-linux:
name: "Rust Cargo Deps"
platform: ubuntu1804
working_directory: ../rust-examples/05-deps-cargo
build_targets:
- "//..."
rust-06-deps-direct-linux:
name: "Rust Direct Deps"
platform: ubuntu1804
working_directory: ../rust-examples/06-deps-direct
build_targets:
- "//..."
rust-07-deps-vendor-linux:
name: "Rust Vendored Deps"
platform: ubuntu1804
working_directory: ../rust-examples/07-deps-vendor
build_targets:
- "//..."
rust-08-grpc-client-server-linux:
name: "Rust grpc"
platform: ubuntu1804
working_directory: ../rust-examples/08-grpc-client-server
build_targets:
- "//:all"
rust-08-grpc-client-server-macos:
name: "Rust grpc"
platform: macos
working_directory: ../rust-examples/08-grpc-client-server
build_targets:
- "//:all"
rust-09-oci-container-linux:
name: "Rust OCI"
platform: ubuntu1804
working_directory: ../rust-examples/09-oci-container
build_targets:
- "//..."
- "//tokio_oci:image"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ bazel-*
target/
# Xcode
*.xcodeproj
node_modules
node_modules
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Note that tutorials for other languages may be found under other repositories:

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

### Rust

* [Building Rust](/rust-examples)

### Frontend

* [Next.js](/frontend/next.js)
Expand Down
1 change: 1 addition & 0 deletions rust-examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.2.1
1 change: 1 addition & 0 deletions rust-examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*/bazel-*
1 change: 1 addition & 0 deletions rust-examples/01-hello-world/.bazelversion
8 changes: 8 additions & 0 deletions rust-examples/01-hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@rules_rust//rust:defs.bzl", "rust_binary")

rust_binary(
name = "bin",
srcs = ["src/main.rs"],
visibility = ["//visibility:public"],
deps = [],
)
21 changes: 21 additions & 0 deletions rust-examples/01-hello-world/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module(
name = "hello_world",
version = "0.0.0",
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.47.1")

# Rust toolchain
RUST_EDITION = "2021"

RUST_VERSION = "1.79.0"

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = RUST_EDITION,
versions = [RUST_VERSION],
)
use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")
Loading

0 comments on commit a905ed1

Please sign in to comment.