Skip to content

Commit 8b473f7

Browse files
authored
Merge pull request #18 from bamler-lab/new-probability
Full `no_std` and `miri` support
2 parents 2ecb9c3 + a969ef3 commit 8b473f7

27 files changed

Lines changed: 729 additions & 349 deletions

File tree

.github/workflows/release.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
args: --release
6565

6666
miri-test:
67+
name: no_std and miri
6768
runs-on: ${{ matrix.os }}
6869
strategy:
6970
fail-fast: false
@@ -101,9 +102,14 @@ jobs:
101102
with:
102103
toolchain: ${{ steps.versions.outputs.rustc }}
103104
profile: minimal
104-
components: miri
105+
components: miri, rust-src
105106
override: true
106107

108+
- name: Test `no_std` compatibility
109+
shell: bash
110+
working-directory: ensure_no_std
111+
run: cargo +${{ steps.versions.outputs.rustc }} build
112+
107113
- name: Run tests in miri
108114
env:
109115
RUSTFLAGS: "-Zrandomize-layout"

.github/workflows/test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
args: --release
8383

8484
miri-test:
85+
name: no_std and miri
8586
runs-on: ${{ matrix.os }}
8687
needs: rust-test
8788
strategy:
@@ -131,9 +132,14 @@ jobs:
131132
with:
132133
toolchain: ${{ steps.versions.outputs.rustc }}
133134
profile: minimal
134-
components: miri
135+
components: miri, rust-src
135136
override: true
136137

138+
- name: Test `no_std` compatibility
139+
shell: bash
140+
working-directory: ensure_no_std
141+
run: cargo +${{ steps.versions.outputs.rustc }} build
142+
137143
- name: Run tests in miri
138144
env:
139145
RUSTFLAGS: "-Zrandomize-layout"

Cargo.lock

Lines changed: 16 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ name = "constriction"
2020

2121
[features]
2222
default = ["std"]
23-
std = ["probability"]
23+
std = []
2424

2525
# Use feature `pybindings` to compile the python extension module that provides
2626
# access to this library from python. This feature is turned off by default
@@ -30,10 +30,11 @@ pybindings = ["ndarray", "numpy", "pyo3"]
3030

3131
[dependencies]
3232
hashbrown = "0.12.3"
33-
num = "0.4"
33+
num-traits = {version = "0.2.15", default-features = false, features = ["libm"]}
3434
smallvec = "1.6.1"
3535

36-
probability = {version = "0.18", optional = true}
36+
libm = "0.2.6"
37+
probability = {version = "0.20"}
3738

3839
ndarray = {version = "0.15", optional = true}
3940
numpy = {version = "0.17.1", optional = true}

benches/lookup.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use constriction::{
1010
BitArray, Pos, Seek,
1111
};
1212
use criterion::{black_box, criterion_group, Criterion};
13-
use num::cast::AsPrimitive;
13+
use num_traits::AsPrimitive;
1414
use rand::{RngCore, SeedableRng};
1515
use rand_xoshiro::Xoshiro256StarStar;
1616

@@ -26,7 +26,7 @@ criterion_group!(
2626
#[cfg(not(miri))]
2727
criterion::criterion_main!(benches);
2828
#[cfg(miri)]
29-
fn main() {} // All benchmarks currently use FFI and therefore can't be tested in miri.
29+
fn main() {} // miri currently doesn't seem to be able to run criterion benchmarks as tests.
3030

3131
fn round_trip_u32_u64_u16_12(c: &mut Criterion) {
3232
round_trip::<u32, u64, u16, 12>(c);
@@ -87,7 +87,7 @@ where
8787
type_name::<Probability>(),
8888
PRECISION
8989
);
90-
c.bench_function(&format!("ans_encoding_{}", label_suffix), |b| {
90+
c.bench_function(&format!("ans_encoding_{label_suffix}"), |b| {
9191
b.iter(|| {
9292
encoder.clear();
9393
encoder
@@ -109,7 +109,7 @@ where
109109
let mut backward_decoder = encoder.into_seekable_decoder();
110110
let reset_snapshot = backward_decoder.pos();
111111

112-
c.bench_function(&format!("ans_backward_decoding_{}", label_suffix), |b| {
112+
c.bench_function(&format!("ans_backward_decoding_{label_suffix}"), |b| {
113113
b.iter(|| {
114114
backward_decoder.seek(black_box(reset_snapshot)).unwrap();
115115
let mut checksum = 1234u16;
@@ -132,7 +132,7 @@ where
132132
let mut forward_decoder = backward_decoder.into_reversed();
133133
let reset_snapshot = forward_decoder.pos();
134134

135-
c.bench_function(&format!("ans_forward_decoding_{}", label_suffix), |b| {
135+
c.bench_function(&format!("ans_forward_decoding_{label_suffix}"), |b| {
136136
b.iter(|| {
137137
forward_decoder.seek(black_box(reset_snapshot)).unwrap();
138138
let mut checksum = 1234u16;
@@ -179,7 +179,7 @@ where
179179
type_name::<Probability>(),
180180
PRECISION
181181
);
182-
c.bench_function(&format!("range_encoding_{}", label_suffix), |b| {
182+
c.bench_function(&format!("range_encoding_{label_suffix}"), |b| {
183183
b.iter(|| {
184184
encoder.clear();
185185
encoder
@@ -200,7 +200,7 @@ where
200200

201201
let mut decoder = encoder.into_decoder().unwrap();
202202

203-
c.bench_function(&format!("range_decoding_{}", label_suffix), |b| {
203+
c.bench_function(&format!("range_decoding_{label_suffix}"), |b| {
204204
b.iter(|| {
205205
decoder.seek(black_box(reset_snapshot)).unwrap();
206206
let mut checksum = 1234u16;

ensure_no_std/.cargo/config.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# We need to cross-compile the core library.
2+
[unstable]
3+
build-std = [
4+
"alloc",
5+
"compiler_builtins",
6+
"core",
7+
]
8+
build-std-features = ["compiler-builtins-mem"]
9+
10+
[build]
11+
rustflags = [
12+
# See https://doc.rust-lang.org/rustc/codegen-options/index.html for possible rustflags
13+
# use custom linker script
14+
"-C",
15+
"link-args=-n -T src/link.ld", # The default of the x86_64-unknown-none built-in Rust compiler target is "pic".
16+
# See: https://github.com/rust-lang/rust/blob/1.62.1/compiler/rustc_target/src/spec/x86_64_unknown_none.rs
17+
# This is not supported by Hedron.
18+
"-C",
19+
"relocation-model=static",
20+
]
21+
target = "x86_64-unknown-none"

ensure_no_std/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)