Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Rust examples 8 - 9 #548

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7b2132c
Fixed and renovated Rust example 08 grpc.
marvin-hansen Sep 1, 2024
c2a6ea8
Merge branch 'bazelbuild:main' into main
marvin-hansen Sep 10, 2024
5a410e5
Cleanup unused files from Rust 08 grpc example.
marvin-hansen Sep 10, 2024
7e0c222
Merge remote-tracking branch 'origin/main'
marvin-hansen Sep 10, 2024
8b0b805
Updated Readme for Rust 08 grpc example.
marvin-hansen Sep 10, 2024
c9e94ce
Updated Rust 08 grpc example.
marvin-hansen Sep 10, 2024
578148b
Merge branch 'bazelbuild:main' into main
marvin-hansen Sep 15, 2024
e8a760d
Renovated Rust example 01
marvin-hansen Sep 15, 2024
9801383
Renovated Rust example 02
marvin-hansen Sep 15, 2024
9903d53
Renovated Rust example 03 and 04
marvin-hansen Sep 15, 2024
60286c4
Renovated remaining Rust examples.
marvin-hansen Sep 15, 2024
9f15000
Resolved Example 5
marvin-hansen Sep 15, 2024
c3e0af6
Merge remote-tracking branch 'origin/main'
marvin-hansen Feb 2, 2025
af67be6
Updated Rust example 01 to Bazel 8
marvin-hansen Feb 2, 2025
edf9528
Updated Rust example 02 to Bazel 8
marvin-hansen Feb 2, 2025
f4822e3
Updated Rust example 03 to Bazel 8
marvin-hansen Feb 2, 2025
ab552a5
Updated Rust example 04 to build with Bazel 8
marvin-hansen Feb 2, 2025
cb6241c
Updated Rust example 05 to build with Bazel 8
marvin-hansen Feb 2, 2025
39107ab
Updated Rust example 06 to build with Bazel 8
marvin-hansen Feb 2, 2025
dceca16
Updated Rust example 07 to build with Bazel 8
marvin-hansen Feb 2, 2025
3f3bd4a
Updated Rust example 09 to build with Bazel 8
marvin-hansen Feb 2, 2025
0686c31
Updated Rust example 08 to build with Bazel 8
marvin-hansen Feb 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion rust-examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2.1
8.0.1
82 changes: 82 additions & 0 deletions rust-examples/01-hello-world/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
###############################################################################
## Bazel Configuration Flags
##
## `.bazelrc` is a Bazel configuration file.
## https://bazel.build/docs/best-practices#bazelrc-file
###############################################################################

# Required on windows
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# https://bazel.build/docs/windows#symlink
startup --windows_enable_symlinks
build:windows --enable_runfiles

###############################################################################
## Build configuration
###############################################################################

# Required for cargo_build_script support before Bazel 7
build --incompatible_merge_fixed_and_default_shell_env

# Enable C++ toolchain resolution.
build --incompatible_enable_cc_toolchain_resolution

# Debug toolchain resolution. Uncomment when needed.
# build --toolchain_resolution_debug='@bazel_tools//tools/cpp:toolchain_type

# Don't create bazel-* symlinks in the WORKSPACE directory.
# Instead, set a prefix and put it in .gitignore
# Uncomment when needed.
# build --symlink_prefix=target-bzl/

# Non-empty glob test is disabled because some Bazels deps fail the test.
# Only use locally and uncomment before pushing to CI.
# build --incompatible_disallow_empty_glob

# This flag improves execution throughput by executing more actions in parallel.
# Number should be no more than twice the number of CPU cores.
# Uncomment when needed.
# build --jobs=32

###############################################################################
## Common configuration
###############################################################################

# Enable Bzlmodby default
common --enable_bzlmod

# Write build outputs in a platform-specific directory;
# avoid outputs being wiped and rewritten when switching between platforms.
common --experimental_platform_in_output_dir

# Enable misc. performance optimizations.
# https://www.buildbuddy.io/blog/debugging-slow-bazel-builds/
# https://www.buildbuddy.io/blog/how-bazel-7-0-makes-your-builds-faster/
common --nolegacy_important_outputs
common --verbose_failures
common --noexperimental_merged_skyframe_analysis_execution

# Enable a more detailed performance profile
common --noslim_profile
common --experimental_profile_include_target_label
common --experimental_profile_include_primary_output

###############################################################################
## Test configuration
###############################################################################

# Reduce test output to just error cases and report timeout warnings.
test --test_output=errors
test --verbose_failures

###############################################################################
## Custom user flags
##
## This should always be the last thing in the `.bazelrc` file to ensure
## consistent behavior when setting flags in that file as `.bazelrc` files are
## evaluated top to bottom.
###############################################################################

try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions rust-examples/01-hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bazel-*
6 changes: 3 additions & 3 deletions rust-examples/01-hello-world/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module(
)

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

# Rust toolchain
RUST_EDITION = "2021"
RUST_EDITION = "2021" # NOTE: 2024 edition will be released with Rust 1.85.0

RUST_VERSION = "1.79.0"
RUST_VERSION = "1.84.1"

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
Expand Down
13,026 changes: 0 additions & 13,026 deletions rust-examples/01-hello-world/MODULE.bazel.lock

This file was deleted.

6 changes: 3 additions & 3 deletions rust-examples/01-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ In this first example, the goal is to build a minimal Hello World Rust binary wi

## Requirements

On your computer, you need:

* Cargo & Rust
* C compiler (gcc, or clang)

Expand All @@ -25,9 +27,7 @@ module(
)

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


bazel_dep(name = "rules_rust", version = "0.50.1")

# Rust toolchain
RUST_EDITION = "2021"
Expand Down
82 changes: 82 additions & 0 deletions rust-examples/02-hello-cross/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
###############################################################################
## Bazel Configuration Flags
##
## `.bazelrc` is a Bazel configuration file.
## https://bazel.build/docs/best-practices#bazelrc-file
###############################################################################

# Required on windows
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# https://bazel.build/docs/windows#symlink
startup --windows_enable_symlinks
build:windows --enable_runfiles

###############################################################################
## Build configuration
###############################################################################

# Required for cargo_build_script support before Bazel 7
build --incompatible_merge_fixed_and_default_shell_env

# Enable C++ toolchain resolution.
build --incompatible_enable_cc_toolchain_resolution

# Debug toolchain resolution. Uncomment when needed.
# build --toolchain_resolution_debug='@bazel_tools//tools/cpp:toolchain_type

# Don't create bazel-* symlinks in the WORKSPACE directory.
# Instead, set a prefix and put it in .gitignore
# Uncomment when needed.
# build --symlink_prefix=target-bzl/

# Non-empty glob test is disabled because some Bazels deps fail the test.
# Only use locally and uncomment before pushing to CI.
# build --incompatible_disallow_empty_glob

# This flag improves execution throughput by executing more actions in parallel.
# Number should be no more than twice the number of CPU cores.
# Uncomment when needed.
# build --jobs=32

###############################################################################
## Common configuration
###############################################################################

# Enable Bzlmodby default
common --enable_bzlmod

# Write build outputs in a platform-specific directory;
# avoid outputs being wiped and rewritten when switching between platforms.
common --experimental_platform_in_output_dir

# Enable misc. performance optimizations.
# https://www.buildbuddy.io/blog/debugging-slow-bazel-builds/
# https://www.buildbuddy.io/blog/how-bazel-7-0-makes-your-builds-faster/
common --nolegacy_important_outputs
common --verbose_failures
common --noexperimental_merged_skyframe_analysis_execution

# Enable a more detailed performance profile
common --noslim_profile
common --experimental_profile_include_target_label
common --experimental_profile_include_primary_output

###############################################################################
## Test configuration
###############################################################################

# Reduce test output to just error cases and report timeout warnings.
test --test_output=errors
test --verbose_failures

###############################################################################
## Custom user flags
##
## This should always be the last thing in the `.bazelrc` file to ensure
## consistent behavior when setting flags in that file as `.bazelrc` files are
## evaluated top to bottom.
###############################################################################

try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions rust-examples/02-hello-cross/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bazel-*
125 changes: 55 additions & 70 deletions rust-examples/02-hello-cross/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,97 +3,82 @@ module(
version = "0.0.0",
)

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

# Rules for cross compilation
bazel_dep(name = "toolchains_musl", version = "0.1.20", dev_dependency = True)

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

# https://github.com/bazel-contrib/toolchains_llvm
bazel_dep(name = "toolchains_llvm", version = "1.0.0")

# https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/repo/http.bzl
http_archive = use_repo_rule("@bazel_tools//:http.bzl", "http_archive")

# Both, cross compilation and MUSL still need a C/C++ toolchain with sysroot.
_BUILD_FILE_CONTENT = """
filegroup(
name = "{name}",
srcs = glob(["*/**"]),
visibility = ["//visibility:public"],
)
"""

# Download sysroot
###############################################################################
# B A Z E L D E P E N D E N C I E S # https://registry.bazel.build/
###############################################################################
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "toolchains_llvm", version = "1.2.0", dev_dependency = True)

###############################################################################
# Small (clang) LLVM toolchain
# https://github.com/dzbarsky/static-clang
###############################################################################

# INTEL/AMD64 Sysroot. LastModified: 2024-04-26T19:15
# https://commondatastorage.googleapis.com/chrome-linux-sysroot/
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "org_chromium_sysroot_linux_x64",
build_file_content = _BUILD_FILE_CONTENT.format(name = "sysroot"),
sha256 = "f6b758d880a6df264e2581788741623320d548508f07ffc2ae6a29d0c13d647d",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/2e7ada854015a4cc60fc812112d261af44213ed0/debian_bullseye_amd64_sysroot.tar.xz"],
name = "sysroot_linux_x64",
build_file = "//build/sysroot:BUILD.bazel",
sha256 = "5df5be9357b425cdd70d92d4697d07e7d55d7a923f037c22dc80a78e85842d2c",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/4f611ec025be98214164d4bf9fbe8843f58533f7/debian_bullseye_amd64_sysroot.tar.xz"],
)

# ARM 64 Sysroot. LastModified: 2024-04-26T18:33
# https://commondatastorage.googleapis.com/chrome-linux-sysroot/
http_archive(
name = "org_chromium_sysroot_linux_aarch64",
build_file_content = _BUILD_FILE_CONTENT.format(name = "sysroot"),
sha256 = "902d1a40a5fd8c3764a36c8d377af5945a92e3d264c6252855bda4d7ef81d3df",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/41a6c8dec4c4304d6509e30cbaf9218dffb4438e/debian_bullseye_arm64_sysroot.tar.xz"],
name = "sysroot_linux_aarch64",
build_file = "//build/sysroot:BUILD.bazel",
sha256 = "d303cf3faf7804c9dd24c9b6b167d0345d41d7fe4bfb7d34add3ab342f6a236c",
urls = ["https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/906cc7c6bf47d4bd969a3221fc0602c6b3153caa/debian_bullseye_arm64_sysroot.tar.xz"],
)

# LLVM setup
# https://github.com/bazel-contrib/toolchains_llvm/tree/0d302de75f6ace071ac616fb274481eedcc20e5a?tab=readme-ov-file#sysroots
# Clang v18.1.2-4
# https://github.com/dzbarsky/static-clang/releases
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")

# LLVM Versions and platforms
# https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/internal/llvm_distributions.bzl
LLVM_VERSIONS = {
"": "16.0.0",
"darwin-aarch64": "16.0.3",
"darwin-x86_64": "15.0.7",
}

# Host LLVM toolchain.
llvm.toolchain(
name = "llvm_toolchain",
llvm_versions = LLVM_VERSIONS,
)
use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")

# X86 LLVM Toolchain with sysroot.
llvm.toolchain(
name = "llvm_toolchain_x86_with_sysroot",
llvm_versions = LLVM_VERSIONS,
llvm_version = "18.1.8",
sha256 = {
# Generate checksums with shasum -a 256 filename.tar.zst
"darwin-aarch64": "41d8dea52d18c4e8b90c4fcd31965f9f297df9f40a38a33d60748dbe7f8330b8",
"darwin-x86_64": "",
"linux-aarch64": "",
"linux-x86_64": "",
},
stdlib = {
"linux-x86_64": "stdc++",
"linux-aarch64": "stdc++",
},
urls = {
"darwin-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/darwin_aarch64.tar.zst"],
"darwin-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/darwin_x86_64.tar.zst"],
"linux-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/linux_aarch64.tar.zst"],
"linux-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/linux_x86_64.tar.zst"],
},
)
llvm.sysroot(
name = "llvm_toolchain_x86_with_sysroot",
label = "@org_chromium_sysroot_linux_x64//:sysroot",
name = "llvm_toolchain",
label = "@sysroot_linux_x64//:sysroot",
targets = ["linux-x86_64"],
)
use_repo(llvm, "llvm_toolchain_x86_with_sysroot")

# ARM (aarch64) LLVM Toolchain with sysroot.
llvm.toolchain(
name = "llvm_toolchain_aarch64_with_sysroot",
llvm_versions = LLVM_VERSIONS,
)
llvm.sysroot(
name = "llvm_toolchain_aarch64_with_sysroot",
label = "@org_chromium_sysroot_linux_aarch64//:sysroot",
name = "llvm_toolchain",
label = "@sysroot_linux_aarch64//:sysroot",
targets = ["linux-aarch64"],
)
use_repo(llvm, "llvm_toolchain_aarch64_with_sysroot")
use_repo(llvm, "llvm_toolchain")

# Register all LLVM toolchains
register_toolchains("@llvm_toolchain//:all")

# Rust toolchain
RUST_EDITION = "2021"
###############################################################################
# Rust toolchain #
###############################################################################
RUST_EDITION = "2021" # NOTE: 2024 will be released with Rust 1.86.0

RUST_VERSION = "1.79.0"
RUST_VERSION = "1.84.1"

# https://github.com/bazelbuild/rules_rust/releases
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = RUST_EDITION,
Expand Down
Loading