Skip to content

Commit 85ec6ca

Browse files
committed
Refactor examples
1 parent 13941f8 commit 85ec6ca

File tree

6 files changed

+49
-24
lines changed

6 files changed

+49
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"crates/stdsimd-verify",
44
"crates/core_arch",
55
"crates/std_detect",
6+
"examples/"
67
]
78
exclude = [
89
"crates/wasm-assert-instr-tests"

ci/run.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cargo_test() {
6262
then
6363
cmd="$cmd -p core_arch"
6464
else
65-
cmd="$cmd -p core_arch -p std_detect"
65+
cmd="$cmd -p core_arch -p std_detect -p stdsimd_examples"
6666
fi
6767
cmd="$cmd -- $2"
6868
if [ "$NORUN" != "1" ]
@@ -109,4 +109,12 @@ case ${TARGET} in
109109
;;
110110
*)
111111
;;
112+
112113
esac
114+
115+
# Test examples
116+
(
117+
cd examples
118+
cargo test
119+
echo test | cargo run --release hex
120+
)

crates/std_detect/Cargo.toml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,14 @@ maintenance = { status = "experimental" }
2424

2525
[dependencies]
2626
libc = "0.2"
27-
cfg-if = "0.1"
27+
cfg-if = { version = "^0.1.6", default-features = false }
28+
rustc-std-workspace-core = { version = "1.0.0", optional = true }
29+
30+
[features]
31+
default = []
32+
rustc-dep-of-std = [ 'libc/rustc-dep-of-std', 'rustc-std-workspace-core' ]
2833

2934
[dev-dependencies]
3035
core_arch = { version = "0.1.3", path = "../core_arch" }
3136
auxv = "0.3.3"
32-
quickcheck = "0.8"
33-
rand = "0.6"
34-
cupid = "0.6.0"
35-
36-
[target.'cfg(target_arch = "wasm32")'.dependencies]
37-
rand = { version = "0.6", features = ["wasm-bindgen"] }
38-
39-
[[example]]
40-
name = "hex"
41-
path = "../../examples/hex.rs"
42-
43-
[[example]]
44-
name = "wasm"
45-
crate-type = ["cdylib"]
46-
path = "../../examples/wasm.rs"
47-
48-
[features]
49-
default = []
37+
cupid = "0.6.0"

crates/std_detect/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#[macro_use(println)]
2828
extern crate std;
2929

30+
extern crate libc;
31+
3032
#[macro_use]
3133
extern crate cfg_if;
32-
extern crate libc;
3334

3435
#[doc(hidden)]
3536
#[unstable(feature = "stdsimd", issue = "27731")]

examples/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "stdsimd_examples"
3+
version = "0.0.0"
4+
authors = [
5+
"Alex Crichton <[email protected]>",
6+
"Andrew Gallant <[email protected]>",
7+
"Gonzalo Brito Gadeschi <[email protected]>",
8+
]
9+
description = "Examples of the stdsimd crate."
10+
11+
[dependencies]
12+
core_arch = { path = "../crates/core_arch" }
13+
std_detect = { path = "../crates/std_detect" }
14+
quickcheck = "0.8"
15+
rand = "0.6"
16+
17+
[target.'cfg(target_arch = "wasm32")'.dependencies]
18+
rand = { version = "0.6", features = ["wasm-bindgen"] }
19+
20+
[[bin]]
21+
name = "hex"
22+
path = "hex.rs"
23+
24+
[[example]]
25+
name = "wasm"
26+
crate-type = ["cdylib"]
27+
path = "wasm.rs"

examples/hex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! You can test out this program via:
1010
//!
11-
//! echo test | cargo +nightly run --release --example hex -p stdsimd
11+
//! echo test | cargo +nightly run --release hex
1212
//!
1313
//! and you should see `746573740a` get printed out.
1414
@@ -289,8 +289,8 @@ mod benches {
289289
len: usize,
290290
f: for<'a> unsafe fn(&[u8], &'a mut [u8]) -> Result<&'a str, usize>,
291291
) {
292-
let input = rand::thread_rng()
293-
.gen_iter::<u8>()
292+
let mut rng = rand::thread_rng();
293+
let input = std::iter::repeat(()).map(|()| rng.gen::<u8>())
294294
.take(len)
295295
.collect::<Vec<_>>();
296296
let mut dst = vec![0; input.len() * 2];

0 commit comments

Comments
 (0)