Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit f773153

Browse files
committed
Add rand_core 0.4.0
Signed-off-by: Eli Ma <eli@patch.sh>
1 parent 6b72894 commit f773153

39 files changed

+3433
-6
lines changed

BUCK

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ cargo.rust_binary(
2121
"//third-party/rust/crates/winapi/0.3.9:winapi", # --config rust.features=everything,impl-debug,impl-default --config rust.target=i686-pc-windows-gnu
2222
# ---
2323

24+
# rand_core
25+
"//third-party/rust/crates/rand_core/0.3.1:rand_core",
26+
"//third-party/rust/crates/rand_core/0.4.0:rand_core",
27+
2428
# autocfg
2529
"//third-party/rust/crates/autocfg/1.4.0:autocfg",
2630

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/proc-macro2/1.0.74:build.bzl", "get_rust_features", "get_rustc_flags")
3+
4+
# proc-macro2 library implementation
5+
# A substitute implementation of the compiler's `proc_macro` API
6+
rust_library(
7+
name = "proc-macro2",
8+
edition = "2021", # Using edition from Cargo.toml
9+
srcs = glob(["src/**/*.rs"]),
10+
crate_root = "src/lib.rs",
11+
features = get_rust_features(),
12+
rustc_flags = get_rustc_flags(),
13+
env = {},
14+
deps = [
15+
"//third-party/rust/crates/unicode-ident/1.0.17:unicode-ident",
16+
],
17+
visibility = ["PUBLIC"],
18+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def get_rust_features():
2+
features_config = read_config("rust", "features", "")
3+
4+
if features_config == "":
5+
# Default features from Cargo.toml if none specified
6+
return ["proc-macro"]
7+
return [f.strip() for f in features_config.split(",") if f.strip()]
8+
9+
def get_rustc_flags():
10+
"""
11+
Get rustc flags based on features.
12+
"""
13+
flags = []
14+
15+
# Add semver_exempt flag for docs.rs compatibility if needed
16+
semver_exempt = read_config("proc_macro2", "semver_exempt", "")
17+
if semver_exempt:
18+
flags.append("--cfg")
19+
flags.append("procmacro2_semver_exempt")
20+
21+
return flags
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/proc-macro2/1.0.83:build.bzl", "get_rust_features", "get_rustc_flags", "get_env")
3+
4+
5+
# proc_macro2 library implementation
6+
rust_library(
7+
name = "proc-macro2",
8+
edition = "2021", # Using edition from Cargo.toml
9+
srcs = glob(["src/**/*.rs"]) + ["build/probe.rs"], # Include probe.rs that build.rs uses
10+
crate_root = "src/lib.rs",
11+
features = get_rust_features(),
12+
rustc_flags = get_rustc_flags(),
13+
env = get_env(),
14+
deps = [
15+
"//third-party/rust/crates/unicode-ident/1.0.17:unicode-ident",
16+
],
17+
visibility = ["PUBLIC"],
18+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
def get_rust_features():
2+
"""
3+
Get comma-separated features from config and convert to a list.
4+
Default to proc-macro if none specified, matching Cargo.toml behavior.
5+
"""
6+
features_config = read_config("rust", "features", "")
7+
8+
if features_config == "":
9+
return ["proc-macro"] # Default from Cargo.toml
10+
return [f.strip() for f in features_config.split(",") if f.strip()]
11+
12+
def get_rustc_flags():
13+
"""
14+
Generate rustc flags based on configuration parameters.
15+
This mimics the functionality of the build.rs script.
16+
"""
17+
flags = []
18+
features = get_rust_features()
19+
rustc_minor = int(read_config("proc_macro2", "rustc_minor", "9999"))
20+
semver_exempt = read_config("proc_macro2", "semver_exempt", "") != ""
21+
docs_rs = read_config("proc_macro2", "docs_rs", "") != ""
22+
rustc_bootstrap = read_config("proc_macro2", "rustc_bootstrap", "") != ""
23+
24+
# Handle semver_exempt (set by either procmacro2_semver_exempt or DOCS_RS)
25+
if semver_exempt or docs_rs:
26+
flags.extend(["--cfg", "procmacro2_semver_exempt"])
27+
28+
# Handle span_locations
29+
if semver_exempt or docs_rs or "span-locations" in features:
30+
flags.extend(["--cfg", "span_locations"])
31+
32+
# Handle no_is_available
33+
if rustc_minor < 57:
34+
flags.extend(["--cfg", "no_is_available"])
35+
36+
# Handle no_source_text
37+
if rustc_minor < 66:
38+
flags.extend(["--cfg", "no_source_text"])
39+
40+
# Handle no_literal_byte_character and no_literal_c_string
41+
if rustc_minor < 79:
42+
flags.extend(["--cfg", "no_literal_byte_character"])
43+
flags.extend(["--cfg", "no_literal_c_string"])
44+
45+
# Handle proc_macro feature condition
46+
if "proc-macro" not in features:
47+
return flags
48+
49+
# Handle wrap_proc_macro
50+
proc_macro_span = rustc_bootstrap
51+
52+
if proc_macro_span or not semver_exempt:
53+
flags.extend(["--cfg", "wrap_proc_macro"])
54+
55+
# Handle proc_macro_span
56+
if proc_macro_span:
57+
flags.extend(["--cfg", "proc_macro_span"])
58+
59+
# Handle super_unstable
60+
if semver_exempt and proc_macro_span:
61+
flags.extend(["--cfg", "super_unstable"])
62+
63+
return flags
64+
65+
def get_env():
66+
"""
67+
Set environment variables for the build.
68+
"""
69+
env = {}
70+
71+
# Set environment variables from config
72+
docs_rs = read_config("proc_macro2", "docs_rs", "")
73+
if docs_rs:
74+
env["DOCS_RS"] = docs_rs
75+
76+
rustc_bootstrap = read_config("proc_macro2", "rustc_bootstrap", "")
77+
if rustc_bootstrap:
78+
env["RUSTC_BOOTSTRAP"] = rustc_bootstrap
79+
80+
return env
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/quote/1.0.35:build.bzl", "get_rust_features")
3+
4+
# Quote library implementation - Rust quasi-quoting syntax extension
5+
rust_library(
6+
name = "quote",
7+
edition = "2018", # Using edition from Cargo.toml
8+
srcs = glob(["src/**/*.rs"]),
9+
crate_root = "src/lib.rs",
10+
features = get_rust_features(),
11+
rustc_flags = [],
12+
env = {},
13+
deps = [
14+
# Conditional configuration for proc-macro2 with features based on our features
15+
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
16+
],
17+
visibility = ["PUBLIC"],
18+
)
19+
20+
# Test target for quote
21+
rust_test(
22+
name = "quote_test",
23+
srcs = glob(["tests/**/*.rs"]), # Include all test files
24+
crate = ":quote",
25+
deps = [
26+
"//third-party/rust/crates/proc-macro2/1.0.74:proc-macro2",
27+
"//third-party/rust/crates/rustversion/1.0:rustversion",
28+
"//third-party/rust/crates/trybuild/1.0.66:trybuild",
29+
],
30+
features = get_rust_features(),
31+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def get_rust_features():
2+
features_config = read_config("rust", "features", "")
3+
4+
if features_config == "":
5+
# Default features from Cargo.toml if none specified
6+
return ["proc-macro"]
7+
return [f.strip() for f in features_config.split(",") if f.strip()]
8+
9+
def get_proc_macro2_features():
10+
"""
11+
Get features for proc-macro2 dependency based on our own features.
12+
"""
13+
features = get_rust_features()
14+
proc_macro2_features = []
15+
16+
# Add proc-macro feature to proc-macro2 if we have it
17+
if "proc-macro" in features:
18+
proc_macro2_features.append("proc-macro")
19+
20+
return proc_macro2_features
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"git": {
3+
"sha1": "3684cc95c7e39ed04a54cb65d1aa4227f3827d57"
4+
}
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")
2+
load("//third-party/rust/crates/rand_core/0.3.1:build.bzl", "get_rust_features")
3+
4+
# This rust_library implements rand_core 0.3.1
5+
rust_library(
6+
name = "rand_core",
7+
edition = "2018", # Using 2018 as this is likely for rand_core 0.3.1
8+
srcs = glob(["src/**/*.rs"]),
9+
crate_root = "src/lib.rs",
10+
features = get_rust_features(),
11+
rustc_flags = [],
12+
env = {},
13+
deps = [
14+
"//third-party/rust/crates/rand_core/0.4.0:rand_core",
15+
],
16+
visibility = ["PUBLIC"],
17+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [0.3.1] - 2019-01-25
8+
- Compatibility shim around version 0.4
9+
10+
## [0.3.0] - 2018-09-24
11+
- Add `SeedableRng::seed_from_u64` for convenient seeding. (#537)
12+
13+
## [0.2.1] - 2018-06-08
14+
- References to a `CryptoRng` now also implement `CryptoRng`. (#470)
15+
16+
## [0.2.0] - 2018-05-21
17+
- Enable the `std` feature by default. (#409)
18+
- Remove `BlockRng{64}::inner` and `BlockRng::inner_mut`; instead making `core` public
19+
- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419)
20+
- Change `BlockRngCore::Results` bound to also require `AsMut<[Self::Item]>`. (#419)
21+
- Implement `std::io::Read` for RngCore. (#434)
22+
23+
## [0.1.0] - 2018-04-17
24+
(Split out of the Rand crate, changes here are relative to rand 0.4.2)
25+
- `RngCore` and `SeedableRng` are now part of `rand_core`. (#288)
26+
- Add modules to help implementing RNGs `impl` and `le`. (#209, #228)
27+
- Add `Error` and `ErrorKind`. (#225)
28+
- Add `CryptoRng` marker trait. (#273)
29+
- Add `BlockRngCore` trait. (#281)
30+
- Add `BlockRng` and `BlockRng64` wrappers to help implementations. (#281, #325)
31+
- Revise the `SeedableRng` trait. (#233)
32+
- Remove default implementations for `RngCore::next_u64` and `RngCore::fill_bytes`. (#288)
33+
- Add `RngCore::try_fill_bytes`. (#225)
34+
35+
## [0.0.1] - 2017-09-14 (yanked)
36+
Experimental version as part of the rand crate refactor.

0 commit comments

Comments
 (0)