Skip to content

Commit

Permalink
v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Oct 16, 2023
2 parents f450e54 + a2ec320 commit 25b9d65
Show file tree
Hide file tree
Showing 27 changed files with 2,987 additions and 1,408 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
default: "buster"
rust-features:
type: string
default: ""
default: "--all-targets"
docker:
- image: rust:<< parameters.rust-version >>-<< parameters.debian-version >>
environment:
Expand All @@ -31,7 +31,7 @@ jobs:
- bigdecimal-cargo-
- run:
name: Check
command: cargo check
command: cargo check << parameters.rust-features >>
- save_cache:
paths:
- /usr/local/cargo
Expand Down
63 changes: 28 additions & 35 deletions .gitlab-ci.yml
Expand Up @@ -28,13 +28,13 @@
before_script:
- rustc --version && cargo --version
script:
- cargo check --tests
- cargo check --all-targets

.script-cargo-build: &script-cargo-build
before_script:
- rustc --version && cargo --version
script:
- cargo build --tests
- cargo build --all-targets

.script-cargo-test: &script-cargo-test
before_script:
Expand Down Expand Up @@ -118,7 +118,7 @@ cargo:check:
<<: *script-cargo-check
script:
# enable property tests for the stable 'pipeline'
- scripts/bigdecimal-property-tests cargo check --tests
- scripts/bigdecimal-property-tests run cargo check --all-targets

cargo:clippy:
stage: check
Expand Down Expand Up @@ -158,7 +158,7 @@ cargo:build-stable:
<<: *script-cargo-build
script:
# enable property tests for the stable 'pipeline'
- scripts/bigdecimal-property-tests cargo build --tests
- scripts/bigdecimal-property-tests run cargo build --all-targets


cargo:test-stable:
Expand All @@ -171,7 +171,7 @@ cargo:test-stable:
<<: *script-cargo-test
script:
# enable property tests for the stable 'pipeline'
- scripts/bigdecimal-property-tests cargo test
- scripts/bigdecimal-property-tests run cargo test


cargo:build:no-std:
Expand All @@ -197,6 +197,29 @@ cargo:test:no-std:
- cargo test --no-default-features --lib


cargo:build:serde:
stage: build
image: akubera/rust:stable
needs:
- cargo:check
variables:
RUST_CACHE_KEY: "stable+serde"
<<: *script-cargo-build
script:
- cargo build --features=serde --all-targets

cargo:test:serde:
stage: test
image: akubera/rust:stable
needs:
- "cargo:build:serde"
variables:
RUST_CACHE_KEY: "stable+serde"
<<: *script-cargo-test
script:
- cargo test --features=serde --all-targets


cargo:build-nightly:
stage: build
image: rustlang/rust:nightly
Expand Down Expand Up @@ -243,39 +266,9 @@ cargo:test-1.43:
<<: *script-cargo-test


cargo:check-1.54:
stage: check
image: "akubera/rust-kcov:1.54.0-bullseye"
rules:
*rules-always-master-otherwise-manual
variables:
RUST_CACHE_KEY: "1.54"
<<: *script-cargo-check

cargo:build-1.54:
stage: build
image: "akubera/rust-kcov:1.54.0-bullseye"
needs:
- "cargo:check-1.54"
variables:
RUST_CACHE_KEY: "1.54"
<<: *script-cargo-build

cargo:test-1.54:
stage: test
needs:
- "cargo:build-1.54"
image: "akubera/rust-kcov:1.54.0-bullseye"
variables:
RUST_CACHE_KEY: "1.54"
<<: *script-cargo-test


cargo:check-1.70:
stage: check
image: "akubera/rust-grcov:1.70.0-bullseye"
rules:
*rules-always-master-otherwise-manual
variables:
RUST_CACHE_KEY: "1.70"
<<: *script-cargo-check
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bigdecimal"
version = "0.4.1"
version = "0.4.2"
authors = ["Andrew Kubera"]
description = "Arbitrary precision decimal numbers"
documentation = "https://docs.rs/bigdecimal"
Expand Down Expand Up @@ -47,6 +47,6 @@ default = ["std"]
string-only = []
std = ["num-bigint/std", "num-integer/std", "num-traits/std"]

[[bench]]
name = "arithmetic"
harness = false
# BENCH: [[bench]]
# BENCH: name = "arithmetic"
# BENCH: harness = false
2 changes: 1 addition & 1 deletion benches/arithmetic.rs
@@ -1,4 +1,4 @@
//! Benchmarks for arithmetic opertaion
//! Benchmarks for arithmetic operation

extern crate criterion;
extern crate bigdecimal;
Expand Down
64 changes: 31 additions & 33 deletions build.rs
@@ -1,50 +1,48 @@
#![allow(clippy::style)]

extern crate autocfg;

use std::env;
use std::path::PathBuf;
use std::path::{Path, PathBuf};


fn main() -> std::io::Result<()> {
fn main() {
let ac = autocfg::new();
ac.emit_rustc_version(1, 70);

let outdir = match std::env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
let outdir_path = PathBuf::from(outdir);
// Option::zip
ac.emit_rustc_version(1, 46);

// Remove this comment if enabled proptests
// ::PROPERTY-TESTS:: autocfg::emit("property_tests");

write_default_precision(&outdir_path, "default_precision.rs")?;
Ok(())
let outdir: PathBuf = std::env::var_os("OUT_DIR").unwrap().into();
write_default_precision_file(&outdir);
write_default_rounding_mode(&outdir);
}

/// Create default_precision.rs, containg definition of constant DEFAULT_PRECISION
fn write_default_precision(outdir_path: &PathBuf, filename: &str) -> std::io::Result<()>
{

let default_prec = env::var("RUST_BIGDECIMAL_DEFAULT_PRECISION")
.map(|s| s.parse::<std::num::NonZeroU32>().expect("$RUST_BIGDECIMAL_DEFAULT_PRECISION must be an integer > 0"))
.map(|nz_num| nz_num.into())
.unwrap_or(100u32);
/// Create default_precision.rs, containing definition of constant DEFAULT_PRECISION loaded in src/lib.rs
fn write_default_precision_file(outdir: &Path) {
let env_var = env::var("RUST_BIGDECIMAL_DEFAULT_PRECISION").unwrap_or_else(|_| "100".to_owned());
println!("cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_PRECISION");

let rust_file_path = outdir.join("default_precision.rs");

let default_precision_rs_path = outdir_path.join(filename);
let default_prec: u32 = env_var
.parse::<std::num::NonZeroU32>()
.expect("$RUST_BIGDECIMAL_DEFAULT_PRECISION must be an integer > 0")
.into();

let default_precision = format!("const DEFAULT_PRECISION: u64 = {};", default_prec);
let rust_file_contents = format!("const DEFAULT_PRECISION: u64 = {};", default_prec);

std::fs::write(rust_file_path, rust_file_contents).unwrap();
}

// Rewriting the file if it already exists with the same contents
// would force a rebuild.
match std::fs::read_to_string(&default_precision_rs_path) {
Ok(existing_contents) if existing_contents == default_precision => {},
_ => {
std::fs::write(&default_precision_rs_path, default_precision)
.expect("Could not write big decimal default-precision file");
}
};
/// Create default_rounding_mode.rs, using value of RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE environment variable
fn write_default_rounding_mode(outdir: &Path) {
let rounding_mode_name = env::var("RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE").unwrap_or_else(|_| "HalfEven".to_owned());
println!("cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE");

println!("cargo:rerun-if-changed={}", default_precision_rs_path.display());
println!("cargo:rerun-if-env-changed={}", "RUST_BIGDECIMAL_DEFAULT_PRECISION");
let rust_file_path = outdir.join("default_rounding_mode.rs");
let rust_file_contents = format!("const DEFAULT_ROUNDING_MODE: RoundingMode = RoundingMode::{};", rounding_mode_name);

Ok(())
std::fs::write(rust_file_path, rust_file_contents).unwrap();
}
10 changes: 5 additions & 5 deletions scripts/benchmark-bigdecimal
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Run Criterion Benchmarks
#
Expand All @@ -14,7 +14,7 @@ mv Cargo.toml.bak Cargo.toml


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

sample_datafile=target/criterion/$name/new/sample.json
if [ -f $sample_datafile ]; then
if [ -f "$sample_datafile" ]; then
echo "<p><a href='${sample_datafile}' class='sample-json'>$name</a>" >> index.html
else
echo "<p>$name</p>" >> index.html
Expand Down
48 changes: 39 additions & 9 deletions scripts/bigdecimal-property-tests
Expand Up @@ -5,15 +5,45 @@
# Tests are defined in src/lib.tests.property-test.rs
#

# enable property-test dependencies in Cargo
sed -i.bak -e 's|# PROPERTY-TESTS: ||' Cargo.toml
enable_property_tests() {
# enable property-test dependencies in Cargo
sed -i.bak -e 's|# PROPERTY-TESTS: ||' Cargo.toml

# include the property-test file in lib.rs
sed -i.bak -e 's|// ::PROPERTY-TESTS:: ||' src/lib.rs
# add the property-test configuration in build.rs
sed -i.bak -e 's|// ::PROPERTY-TESTS:: ||' build.rs
}

# Run commands
"$@"

# Restore Cargo.toml with backup
mv Cargo.toml.bak Cargo.toml
mv src/lib.rs.bak src/lib.rs
restore_disabled_property_tests() {
# Restore Cargo.toml with backup
mv Cargo.toml.bak Cargo.toml
mv build.rs.bak build.rs
}


DEFAULT_CMD=run
CMD=${1:-$DEFAULT_CMD}
shift

case "${CMD}" in
run)
enable_property_tests
# Run commands
"$@"
restore_disabled_property_tests
;;

test)
enable_property_tests
cargo test "$@"
restore_disabled_property_tests
;;

enable)
enable_property_tests
;;

disable)
restore_disabled_property_tests
;;
esac
10 changes: 5 additions & 5 deletions scripts/fetch-benchmark-data.sh
Expand Up @@ -16,16 +16,16 @@ function fetch_benchmark_bigdecimal_file() {
local FILENAME="random-bigdecimals-$1.txt"
local FILEPATH=$TEST_DATA_DIR/$FILENAME

if [ -e $FILEPATH ]; then
if [ -e "$FILEPATH" ]; then
echo "exists: $FILEPATH"
else
local URL=${GITLAB_URL_PATTERN//<FILENAME>/$FILENAME}
echo "fetching: $FILEPATH from $URL"

if [ $CURL ]; then
$CURL -s --fail -L $URL -o "$FILEPATH"
elif [ $WGET ]; then
$WGET --quiet $URL -O "$FILEPATH"
if [ "$CURL" ]; then
$CURL -s --fail -L "$URL" -o "$FILEPATH"
elif [ "$WGET" ]; then
"$WGET" --quiet "$URL" -O "$FILEPATH"
else
echo "No supported fetching program"
fi
Expand Down

0 comments on commit 25b9d65

Please sign in to comment.