Skip to content

Commit 62e4c2e

Browse files
authored
Merge branch 'akubera:trunk' into trunk
2 parents 8649276 + 5d8e09f commit 62e4c2e

32 files changed

+3426
-1787
lines changed

.circleci/config.yml

+66-28
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
version: 2.1
22
orbs:
3-
# codecov: codecov/codecov@3.2.4
4-
rust: circleci/[email protected].0
3+
# codecov: codecov/codecov@3.3.0
4+
rust: circleci/[email protected].1
55

66
jobs:
77
build-and-test:
88
parameters:
99
rust-version:
1010
type: string
11-
default: "1.69.0"
11+
default: "1.75.0"
1212
debian-version:
1313
type: string
14-
default: "buster"
14+
default: "bookworm"
1515
rust-features:
1616
type: string
1717
default: "--all-targets"
@@ -49,7 +49,7 @@ jobs:
4949
type: string
5050
debian-version:
5151
type: string
52-
default: "bullseye"
52+
default: "bookworm"
5353
machine: true
5454
steps:
5555
- checkout
@@ -65,54 +65,92 @@ jobs:
6565
sh -c 'cargo test -q --no-run && kcov-rust && upload-kcov-results-to-codecov'
6666
- store_artifacts:
6767
path: target/cov
68-
# - store_test_results:
69-
# path: target
7068

7169
lint-check:
7270
docker:
73-
- image: cimg/rust:1.69
71+
- image: cimg/rust:1.75
7472
steps:
7573
- checkout
74+
- run:
75+
name: Generate cargo.lock
76+
command: cargo generate-lockfile
7677
- rust/build:
7778
with_cache: false
7879
# - rust/format
79-
# - rust/clippy
80+
- rust/clippy
8081
- rust/test
8182
- run:
8283
name: Build examples
8384
command: cargo build --examples
8485

86+
cargo-semver-check:
87+
docker:
88+
- image: "akubera/rust:stable"
89+
steps:
90+
- checkout
91+
- run:
92+
name: Tool Versions
93+
command: >
94+
rustc --version
95+
&& cargo --version
96+
&& cargo semver-checks --version
97+
- run:
98+
name: cargo semver-checks
99+
command: cargo semver-checks --verbose
100+
- run:
101+
name: cargo semver-checks (no-std)
102+
command: cargo semver-checks --verbose --only-explicit-features
103+
85104
workflows:
86105
version: 2
87106
cargo:build-and-test:
88107
jobs:
108+
- rust/lint-test-build:
109+
name: "lint-test-build:stable"
110+
release: true
111+
version: "1.75"
112+
pre-steps:
113+
- checkout
114+
- run:
115+
command: cargo generate-lockfile
116+
- rust/lint-test-build:
117+
name: "lint-test-build:1.56"
118+
release: true
119+
version: "1.56"
120+
89121
- lint-check
122+
123+
- build-and-test:
124+
name: build-and-test:MSRV
125+
rust-version: "1.43.1"
126+
debian-version: "buster"
127+
90128
- build-and-test:
91-
matrix:
92-
parameters:
93-
rust-version:
94-
- "1.43.1"
95-
- "1.54.0"
129+
name: build-and-test:MSRV:serde
130+
rust-version: "1.43.1"
131+
debian-version: "buster"
132+
rust-features: "--all-targets --features='serde'"
96133

97134
- build-and-test:
98-
name: build-and-test:latest
99-
debian-version: "bullseye"
135+
name: build-and-test:latest
100136

101137
- build-and-test:
102-
matrix:
103-
parameters:
104-
rust-version:
105-
- "1.43.1"
106-
- "1.69.0"
107-
rust-features:
108-
- "--features='serde'"
109-
- "--features='serde,string-only'"
138+
name: build-and-test:latest:serde
139+
rust-features: "--all-targets --features='serde'"
110140

111141
- build-and-test:
112-
name: build-and-test:no-default-features
113-
rust-features: "--no-default-features"
142+
name: build-and-test:no_std
143+
rust-features: "--no-default-features"
144+
145+
- build-and-test:
146+
name: build-and-test:serde+no_std
147+
rust-features: "--no-default-features --features='serde'"
148+
149+
- cargo-semver-check:
150+
requires:
151+
- build-and-test:latest:serde
114152

115153
- upload-coverage:
116-
rust-version: "1.69.0"
154+
rust-version: "1.75.0"
117155
requires:
118-
- build-and-test:latest
156+
- build-and-test:latest:serde

.gitlab-ci.yml

+26-33
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ cargo:check:
118118
<<: *script-cargo-check
119119
script:
120120
# enable property tests for the stable 'pipeline'
121-
- scripts/bigdecimal-property-tests cargo check --all-targets
121+
- scripts/bigdecimal-property-tests run cargo check --all-targets
122122

123123
cargo:clippy:
124124
stage: check
@@ -158,7 +158,7 @@ cargo:build-stable:
158158
<<: *script-cargo-build
159159
script:
160160
# enable property tests for the stable 'pipeline'
161-
- scripts/bigdecimal-property-tests cargo build --all-targets
161+
- scripts/bigdecimal-property-tests run cargo build --all-targets
162162

163163

164164
cargo:test-stable:
@@ -171,7 +171,7 @@ cargo:test-stable:
171171
<<: *script-cargo-test
172172
script:
173173
# enable property tests for the stable 'pipeline'
174-
- scripts/bigdecimal-property-tests cargo test
174+
- scripts/bigdecimal-property-tests run cargo test
175175

176176

177177
cargo:build:no-std:
@@ -197,6 +197,29 @@ cargo:test:no-std:
197197
- cargo test --no-default-features --lib
198198

199199

200+
cargo:build:serde:
201+
stage: build
202+
image: akubera/rust:stable
203+
needs:
204+
- cargo:check
205+
variables:
206+
RUST_CACHE_KEY: "stable+serde"
207+
<<: *script-cargo-build
208+
script:
209+
- cargo build --features=serde --all-targets
210+
211+
cargo:test:serde:
212+
stage: test
213+
image: akubera/rust:stable
214+
needs:
215+
- "cargo:build:serde"
216+
variables:
217+
RUST_CACHE_KEY: "stable+serde"
218+
<<: *script-cargo-test
219+
script:
220+
- cargo test --features=serde --all-targets
221+
222+
200223
cargo:build-nightly:
201224
stage: build
202225
image: rustlang/rust:nightly
@@ -243,39 +266,9 @@ cargo:test-1.43:
243266
<<: *script-cargo-test
244267

245268

246-
cargo:check-1.54:
247-
stage: check
248-
image: "akubera/rust-kcov:1.54.0-bullseye"
249-
rules:
250-
*rules-always-master-otherwise-manual
251-
variables:
252-
RUST_CACHE_KEY: "1.54"
253-
<<: *script-cargo-check
254-
255-
cargo:build-1.54:
256-
stage: build
257-
image: "akubera/rust-kcov:1.54.0-bullseye"
258-
needs:
259-
- "cargo:check-1.54"
260-
variables:
261-
RUST_CACHE_KEY: "1.54"
262-
<<: *script-cargo-build
263-
264-
cargo:test-1.54:
265-
stage: test
266-
needs:
267-
- "cargo:build-1.54"
268-
image: "akubera/rust-kcov:1.54.0-bullseye"
269-
variables:
270-
RUST_CACHE_KEY: "1.54"
271-
<<: *script-cargo-test
272-
273-
274269
cargo:check-1.70:
275270
stage: check
276271
image: "akubera/rust-grcov:1.70.0-bullseye"
277-
rules:
278-
*rules-always-master-otherwise-manual
279272
variables:
280273
RUST_CACHE_KEY: "1.70"
281274
<<: *script-cargo-check

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bigdecimal"
3-
version = "0.4.2+dev"
3+
version = "0.4.3+dev"
44
authors = ["Andrew Kubera"]
55
description = "Arbitrary precision decimal numbers"
66
documentation = "https://docs.rs/bigdecimal"
@@ -28,7 +28,7 @@ serde = { version = "1.0", optional = true, default-features = false }
2828

2929
[dev-dependencies]
3030
paste = "1"
31-
serde_json = "<1.0.101"
31+
serde_test = "<1.0.176"
3232
siphasher = { version = "0.3.10", default-features = false }
3333
# The following dev-dependencies are only required for benchmarking
3434
# (use the `benchmark-bigdecimal` script to uncomment these and run benchmarks)

benches/arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Benchmarks for arithmetic opertaion
1+
//! Benchmarks for arithmetic operation
22
33
extern crate criterion;
44
extern crate bigdecimal;

build.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
#![allow(clippy::style)]
21

32
use std::env;
4-
use std::path::PathBuf;
3+
use std::path::{Path, PathBuf};
4+
55

66
fn main() {
77
let ac = autocfg::new();
88
ac.emit_rustc_version(1, 70);
99

10+
// Option::zip
11+
ac.emit_rustc_version(1, 46);
12+
13+
// Remove this comment if enabled proptests
14+
// ::PROPERTY-TESTS:: autocfg::emit("property_tests");
15+
16+
let outdir: PathBuf = std::env::var_os("OUT_DIR").unwrap().into();
17+
write_default_precision_file(&outdir);
18+
write_default_rounding_mode(&outdir);
19+
}
20+
21+
22+
/// Create default_precision.rs, containing definition of constant DEFAULT_PRECISION loaded in src/lib.rs
23+
fn write_default_precision_file(outdir: &Path) {
1024
let env_var = env::var("RUST_BIGDECIMAL_DEFAULT_PRECISION").unwrap_or_else(|_| "100".to_owned());
1125
println!("cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_PRECISION");
1226

13-
let outdir = std::env::var_os("OUT_DIR").unwrap();
14-
let rust_file_path = PathBuf::from(outdir).join("default_precision.rs");
27+
let rust_file_path = outdir.join("default_precision.rs");
1528

1629
let default_prec: u32 = env_var
1730
.parse::<std::num::NonZeroU32>()
@@ -21,4 +34,15 @@ fn main() {
2134
let rust_file_contents = format!("const DEFAULT_PRECISION: u64 = {};", default_prec);
2235

2336
std::fs::write(rust_file_path, rust_file_contents).unwrap();
24-
}
37+
}
38+
39+
/// Create default_rounding_mode.rs, using value of RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE environment variable
40+
fn write_default_rounding_mode(outdir: &Path) {
41+
let rounding_mode_name = env::var("RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE").unwrap_or_else(|_| "HalfEven".to_owned());
42+
println!("cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE");
43+
44+
let rust_file_path = outdir.join("default_rounding_mode.rs");
45+
let rust_file_contents = format!("const DEFAULT_ROUNDING_MODE: RoundingMode = RoundingMode::{};", rounding_mode_name);
46+
47+
std::fs::write(rust_file_path, rust_file_contents).unwrap();
48+
}

examples/floating-precision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bigdecimal::BigDecimal;
44
use std::str::FromStr;
55

66
fn main() {
7-
let input = std::env::args().skip(1).next().unwrap_or("0.7".to_string());
7+
let input = std::env::args().nth(1).unwrap_or("0.7".to_string());
88
let decimal = BigDecimal::from_str(&input).expect("invalid decimal");
99
let floating = f32::from_str(&input).expect("invalid float");
1010

examples/simple-math.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ sum mut: 48.00000000000000
2121
fn main() {
2222
println!("Hello, Big Decimals!");
2323
let input = "0.8";
24-
let dec = BigDecimal::from_str(&input).unwrap();
25-
let float = f32::from_str(&input).unwrap();
24+
let dec = BigDecimal::from_str(input).unwrap();
25+
let float = f32::from_str(input).unwrap();
2626
println!("Input ({}) with 10 decimals: {} vs {})", input, dec, float);
2727

2828
let bd_square = dec.square();

scripts/benchmark-bigdecimal

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Run Criterion Benchmarks
44
#
@@ -14,7 +14,7 @@ mv Cargo.toml.bak Cargo.toml
1414

1515

1616
# store extra things for the benchmarking report
17-
if [ ! -z "$BENCHMARK_EXTRAS" ]; then
17+
if [ -n "$BENCHMARK_EXTRAS" ]; then
1818
cat <<EOF > index.html
1919
<!doctype html>
2020
<head>
@@ -36,12 +36,12 @@ EOF
3636
# Add svg plots to index html
3737
find target/criterion -name 'pdf.svg' -type f -print0 |
3838
sort -z |
39-
while read -d $'\0' svg_file
39+
while read -r -d $'\0' svg_file
4040
do
41-
name=$(echo $svg_file | cut -d '/' -f 3)
41+
name=$(echo "$svg_file" | cut -d '/' -f 3)
4242

4343
sample_datafile=target/criterion/$name/new/sample.json
44-
if [ -f $sample_datafile ]; then
44+
if [ -f "$sample_datafile" ]; then
4545
echo "<p><a href='${sample_datafile}' class='sample-json'>$name</a>" >> index.html
4646
else
4747
echo "<p>$name</p>" >> index.html

0 commit comments

Comments
 (0)