-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vinh Tran
committed
Nov 9, 2023
1 parent
b78cd8a
commit 464f03b
Showing
6 changed files
with
41 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
examples/toolchain-to-rebuild-std/hello_lib/src/greeter.rs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
examples/toolchain-to-rebuild-std/hello_lib/tests/greeting.rs
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
examples/toolchain-to-rebuild-std/hello_program/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,28 @@ | ||
load( | ||
"@rules_rust//rust:defs.bzl", | ||
"rust_binary", | ||
) | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# This program uses std::os::wasi that is only available on WASI | ||
# When running `bazel build` with `--platforms=//:aarch64-apple-darwin` | ||
# rust toolchain is resolved to rebuild `std` for WASI specifically | ||
|
||
# As a counterexample, try removing `target_compatible_with` attr and rebuild | ||
# with `--platforms=//:aarch64-apple-darwin`. You'll see the following error | ||
# --> hello_program/src/main_with_wasi.rs:4:14 | ||
# | | ||
# 4 | use std::os::wasi::prelude::*; | ||
# | ^^^^ could not find `wasi` in `os` | ||
# which is expected because std is now built for aarch64-apple-darwin. | ||
rust_binary( | ||
name = "program_with_wasi", | ||
srcs = [ | ||
"src/main_with_wasi.rs", | ||
], | ||
target_compatible_with = select({ | ||
"@rules_rust//rust/platform:wasm32-wasi": [], | ||
"//conditions:default": ["@platforms//:incompatible"], | ||
}), | ||
) |
13 changes: 13 additions & 0 deletions
13
examples/toolchain-to-rebuild-std/hello_program/src/main_with_wasi.rs
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,13 @@ | ||
// Copied from https://doc.rust-lang.org/std/os/wasi/index.html#examples | ||
|
||
use std::fs::File; | ||
use std::os::wasi::prelude::*; | ||
|
||
fn main() -> std::io::Result<()> { | ||
let f = File::create("foo.txt")?; | ||
let fd = f.as_raw_fd(); | ||
|
||
// use fd with native WASI bindings | ||
|
||
Ok(()) | ||
} |