1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 08:34:07 +02:00

switch flake setup

This commit is contained in:
Robin Appelman 2024-09-24 23:20:29 +02:00
commit 25e7d443b5
4 changed files with 92 additions and 226 deletions

View file

@ -3,7 +3,7 @@ on: [push, pull_request]
name: Continuous integration
jobs:
check:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -12,76 +12,17 @@ jobs:
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#check
msrv:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#msrv
clippy:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#clippy
tests:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#test
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#fmt
miri-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- id: set-matrix
run: echo "matrix={\"target\":$(nix eval --json ".#miriTargets.x86_64-linux")}" | tee $GITHUB_OUTPUT
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix flake check --keep-going
miri-tests:
runs-on: ubuntu-latest
needs: [tests, miri-matrix]
needs: [checks]
strategy:
fail-fast: false
matrix: ${{fromJson(needs.miri-matrix.outputs.matrix)}}
matrix:
toolchain:
["x86_64-unknown-linux-musl", "mips64-unknown-linux-gnuabi64"]
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
@ -89,13 +30,18 @@ jobs:
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix develop .#miri -c cargo miri test --target ${{ matrix.target }}
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix run .#miri -- test --target ${{ matrix.target }}
semver:
runs-on: ubuntu-latest
needs: check
needs: checks
steps:
- uses: actions/checkout@v4
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
- uses: cachix/install-nix-action@v27
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix run .#semver-checks

View file

@ -10,19 +10,19 @@ The main way of reading the binary data is to first create a `BitReadBuffer` ,wr
Once you have a BitStream, there are 2 different approaches of reading data
- read primitives, Strings and byte arrays, using `read_bool`, `read_int`, `read_float`, `read_bytes` and `read_string`
- read any type implementing the `BitRead` or `BitReadSized` traits using `read` and `read_sized`
- `BitRead` is for types that can be read without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)
- `BitReadSized` is for types that require external sizing information to be read (fixed length strings, arbitrary length integers
- read primitives, Strings and byte arrays, using `read_bool`, `read_int`, `read_float`, `read_bytes` and `read_string`
- read any type implementing the `BitRead` or `BitReadSized` traits using `read` and `read_sized`
- `BitRead` is for types that can be read without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)
- `BitReadSized` is for types that require external sizing information to be read (fixed length strings, arbitrary length integers
The `BitRead` and `BitReadSized` traits can be used with `#[derive]` if all fields implement `BitRead` or `BitReadSized`.
For writing the data you wrap the output `Vec` into a `BitWriteStream` which can then be used in a manner similar to the `BitReadStream`
- write primitives, Strings and byte arrays, using `write_bool`, `write_int`, `write_float`, `write_bytes` and `write_string`
- write any type implementing the `BitWrite` or `BitWriteSized` traits using `write` and `write_sized`
- `BitWrite` is for types that can be written without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)
- `BitWriteSized` is for types that require external sizing information to be written (fixed length strings, arbitrary length integers
- write primitives, Strings and byte arrays, using `write_bool`, `write_int`, `write_float`, `write_bytes` and `write_string`
- write any type implementing the `BitWrite` or `BitWriteSized` traits using `write` and `write_sized`
- `BitWrite` is for types that can be written without requiring any size info (e.g. null-terminal strings, floats, whole integers, etc)
- `BitWriteSized` is for types that require external sizing information to be written (fixed length strings, arbitrary length integers
Just like the read counterparts, `BitWrite` and `BitWriteSized` traits can be used with `#[derive]` if all fields implement `BitWrite` or `BitWriteSized`.
@ -56,14 +56,14 @@ write_stream.write(&ComplexType {
second: 12,
third: true
})?;
```
```
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
at your option.

103
flake.lock generated
View file

@ -1,32 +1,69 @@
{
"nodes": {
"naersk": {
"crane": {
"locked": {
"lastModified": 1727060013,
"narHash": "sha256-/fC5YlJy4IoAW9GhkJiwyzk0K/gQd9Qi4rRcoweyG9E=",
"owner": "ipetkov",
"repo": "crane",
"rev": "6b40cc876c929bfe1e3a24bf538ce3b5622646ba",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flakelight": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1721727458,
"narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=",
"lastModified": 1727095190,
"narHash": "sha256-eZfUxkPefTP5fknpr2/X+snNysEj830Ft1IaW7VafFE=",
"owner": "nix-community",
"repo": "naersk",
"rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11",
"repo": "flakelight",
"rev": "9e0f7e360688187ed3d7d8b033028e0d3473aa2c",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"repo": "flakelight",
"type": "github"
}
},
"mill-scale": {
"inputs": {
"crane": "crane",
"flakelight": [
"flakelight"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1727556185,
"narHash": "sha256-pEUzAE5WRpPGQYeG/U2mftfHAn2q4aO1pefJNY2EoVw=",
"owner": "icewind1991",
"repo": "mill-scale",
"rev": "823fb3493cb4838c81627821f383af918db33a7f",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "mill-scale",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1726838390,
"narHash": "sha256-NmcVhGElxDbmEWzgXsyAjlRhUus/nEqPC5So7BOJLUM=",
"lastModified": 1726969270,
"narHash": "sha256-8fnFlXBgM/uSvBlLWjZ0Z0sOdRBesyNdH0+esxqizGc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101",
"rev": "23cbb250f3bf4f516a2d0bf03c51a30900848075",
"type": "github"
},
"original": {
@ -37,24 +74,25 @@
},
"root": {
"inputs": {
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"utils": "utils"
"flakelight": "flakelight",
"mill-scale": "mill-scale",
"nixpkgs": "nixpkgs"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"mill-scale",
"flakelight",
"nixpkgs"
]
},
"locked": {
"lastModified": 1726972233,
"narHash": "sha256-FlL/bNESOtDQoczRhmPfReNAmLqVg+dAX4HectPOOf0=",
"lastModified": 1727058553,
"narHash": "sha256-tY/UU3Qk5gP/J0uUM4DZ6wo4arNLGAVqLKBotILykfQ=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "36d73192555e569d27579f6c486fea3ab768823c",
"rev": "edc5b0f896170f07bd39ad59d6186fcc7859bbb2",
"type": "github"
},
"original": {
@ -62,39 +100,6 @@
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

107
flake.nix
View file

@ -1,101 +1,16 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.05";
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
flakelight = {
url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs";
};
mill-scale = {
url = "github:icewind1991/mill-scale";
inputs.flakelight.follows = "flakelight";
};
};
outputs = { mill-scale, ... }: mill-scale ./. {
devShell.packages = pkgs: with pkgs; [ cargo-expand ];
};
outputs = {
self,
nixpkgs,
utils,
naersk,
rust-overlay,
}:
utils.lib.eachDefaultSystem (system: let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib callPackage rust-bin mkShell;
inherit (builtins) listToAttrs fromTOML readFile;
inherit (lib.sources) sourceByRegex;
toolchain = rust-bin.stable.latest.default;
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
msrvToolchain = rust-bin.stable."${msrv}".default;
miriToolchain = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "miri" "rust-src" ];
});
naersk' = callPackage naersk {
rustc = toolchain;
cargo = toolchain;
};
msrvNaersk = callPackage naersk {
rustc = msrvToolchain;
cargo = msrvToolchain;
};
src = sourceByRegex ./. ["Cargo.*" "(src|tests|bitbuffer_derive|benches)(/.*)?"];
naerskOpt = {
pname = "bitbuffer";
root = src;
copySources = ["bitbuffer_derive"];
};
in rec {
packages = {
check = naersk'.buildPackage (naerskOpt // {
mode = "check";
});
test = naersk'.buildPackage (naerskOpt // {
mode = "test";
cargoTestOptions = x: x ++ ["--all-features"];
});
clippy = naersk'.buildPackage (naerskOpt // {
mode = "clippy";
});
fmt = naersk'.buildPackage (naerskOpt // {
mode = "fmt";
});
msrv = msrvNaersk.buildPackage (naerskOpt // {
mode = "check";
});
};
miriTargets = [
"x86_64-unknown-linux-musl" # little-endian
"mips64-unknown-linux-gnuabi64" # big-endian
];
devShells = let
tools = with pkgs; [
bacon
cargo-edit
cargo-outdated
(writeShellApplication {
name = "cargo-expand";
runtimeInputs = [cargo-expand toolchain];
text = ''
# shellcheck disable=SC2068
RUSTC_BOOTSTRAP=1 cargo-expand $@
'';
})
cargo-semver-checks
];
in {
default = mkShell {
nativeBuildInputs = [toolchain] ++ tools;
};
msrv = mkShell {
nativeBuildInputs = [msrvToolchain] ++ tools;
};
miri = mkShell {
nativeBuildInputs = [miriToolchain] ++ tools;
};
};
});
}