Skip to content

Commit a4b1dde

Browse files
committed
feat: initial API
- Alignment types driven by the `alignment` module. - `AlignedBytes` -- aligned container - `AlignedSlice` -- type guarantee on alignment of `&[u8]` - `AlignedBlockIterator` -- iterate aligned blocks of a slice. - Quality of life implementations of `Deref` and `std::cmp` traits. Note: This is the initial commit.
0 parents  commit a4b1dde

19 files changed

+1563
-0
lines changed

.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = "-C target-feature=+avx2"

.github/workflows/metadata.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# cspell:disable
2+
name: Metadata
3+
4+
on:
5+
push:
6+
branches: [ main, ci ]
7+
8+
jobs:
9+
changelog-and-dependencies:
10+
name: CHANGELOG and deps
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Generate a changelog
18+
uses: orhun/git-cliff-action@v1
19+
with:
20+
config: cliff.toml
21+
args: --verbose
22+
env:
23+
OUTPUT: CHANGELOG.md
24+
- name: Install graphviz
25+
uses: ts-graphviz/setup-graphviz@v1
26+
- name: Cache restore
27+
id: cache-restore
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cargo/bin/
32+
~/.cargo/registry/index/
33+
~/.cargo/registry/cache/
34+
~/.cargo/git/db/
35+
target/
36+
key: metadata-cargo-${{ hashFiles('**/Cargo.toml') }}
37+
- name: Rustup stable toolchain
38+
uses: actions-rs/toolchain@v1
39+
with:
40+
toolchain: stable
41+
override: true
42+
default: true
43+
- name: Install cargo-deps
44+
if: steps.cache-restore.outputs.cache-hit != 'true'
45+
uses: actions-rs/cargo@v1
46+
with:
47+
command: install
48+
args: cargo-deps
49+
env:
50+
CARGO_TARGET_DIR: target/
51+
- name: Build all features
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: build
55+
args: --all-features
56+
env:
57+
RUSTFLAGS: "-C target-feature=+avx2"
58+
- name: Generate deps.png
59+
run: cargo deps | dot -Tpng > deps.png
60+
- name: Commit
61+
uses: EndBug/add-and-commit@v9
62+
with:
63+
default_author: github_actions
64+
message: "chore: update CHANGELOG.md and deps.png"
65+
push: true

.github/workflows/miri.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# cspell:disable
2+
name: Miri
3+
4+
on:
5+
push:
6+
branches: [ main, ci ]
7+
schedule:
8+
- cron: '0 0 * * *'
9+
10+
jobs:
11+
miri:
12+
name: Miri matrix
13+
runs-on: ${{ matrix.target.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
target:
18+
- os: ubuntu-latest
19+
triple: x86_64-unknown-linux-gnu
20+
simd: true
21+
feature: avx2
22+
- os: ubuntu-latest
23+
triple: aarch64-unknown-linux-gnu
24+
simd: false
25+
- os: ubuntu-latest
26+
triple: i686-unknown-linux-gnu
27+
simd: true
28+
feature: avx2
29+
- os: ubuntu-latest
30+
triple: arm-unknown-linux-gnueabihf
31+
simd: false
32+
- os: ubuntu-latest
33+
triple: mips-unknown-linux-gnu
34+
simd: false
35+
- os: ubuntu-latest
36+
triple: mips64-unknown-linux-gnuabi64
37+
simd: false
38+
- os: windows-latest
39+
triple: i686-pc-windows-gnu
40+
simd: true
41+
feature: avx2
42+
- os: windows-latest
43+
triple: i686-pc-windows-msvc
44+
simd: true
45+
feature: avx2
46+
- os: ubuntu-latest # xargo fails on macos-latest for some reason
47+
triple: x86_64-apple-darwin
48+
simd: true
49+
feature: avx2
50+
steps:
51+
- name: Checkout sources
52+
uses: actions/checkout@v3
53+
- name: Rustup nightly toolchain
54+
uses: actions-rs/toolchain@v1
55+
with:
56+
toolchain: nightly
57+
components: miri
58+
override: true
59+
default: true
60+
- name: Miri test ${{ matrix.target.simd == true && 'simd' || '' }}
61+
uses: actions-rs/cargo@v1
62+
with:
63+
command: miri
64+
args: test --target ${{ matrix.target.triple }} ${{ matrix.target.simd == true && '' || '--no-default-features' }}
65+
env:
66+
RUSTFLAGS: ${{ matrix.target.feature && format('-C target-feature=+{0}', matrix.target.feature) || '' }}
67+
MIRIFLAGS: "-Zmiri-symbolic-alignment-check -Zmiri-strict-provenance"
68+
MIRI_BACKTRACE: 1

.github/workflows/rust.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# cspell:disable
2+
name: Rust
3+
4+
on:
5+
push:
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ main ]
9+
schedule:
10+
- cron: '0 0 * * *'
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
RUST_BACKTRACE: 1
15+
16+
jobs:
17+
test:
18+
name: Test matrix
19+
runs-on: ${{ matrix.os }}
20+
strategy:
21+
fail-fast: true
22+
matrix:
23+
rust:
24+
- stable
25+
- nightly
26+
os:
27+
- ubuntu-latest
28+
- macos-latest
29+
- windows-latest
30+
target_feature:
31+
- avx2
32+
steps:
33+
- name: Checkout sources
34+
uses: actions/checkout@v3
35+
- name: Rustup ${{ matrix.rust }} toolchain
36+
uses: actions-rs/toolchain@v1
37+
with:
38+
toolchain: ${{ matrix.rust }}
39+
override: true
40+
default: true
41+
- name: Cache restore
42+
id: cache-restore
43+
uses: actions/cache@v3
44+
with:
45+
path: |
46+
~/.cargo/bin/
47+
~/.cargo/registry/index/
48+
~/.cargo/registry/cache/
49+
~/.cargo/git/db/
50+
target/
51+
key: ${{ matrix.os }}-${{ matrix.rust }}-${{ matrix.target_feature }}-cargo-${{ hashFiles('**/Cargo.toml') }}
52+
- name: Install cargo-all-features
53+
if: steps.cache-restore.outputs.cache-hit != 'true'
54+
uses: actions-rs/cargo@v1
55+
with:
56+
command: install
57+
args: cargo-all-features
58+
env:
59+
CARGO_TARGET_DIR: target/
60+
- name: Build all feature sets
61+
uses: actions-rs/cargo@v1
62+
with:
63+
command: build-all-features
64+
env:
65+
RUSTFLAGS: "-C target-feature=+${{ matrix.target_feature }} --deny warnings"
66+
- name: Test all feature sets
67+
uses: actions-rs/cargo@v1
68+
with:
69+
command: test-all-features
70+
env:
71+
RUSTFLAGS: "-C target-feature=+${{ matrix.target_feature }} --deny warnings"
72+
73+
clippy:
74+
name: Clippy (stable)
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v3
78+
- name: Rustup stable toolchain
79+
uses: actions-rs/toolchain@v1
80+
with:
81+
toolchain: stable
82+
components: clippy
83+
override: true
84+
default: true
85+
- name: Build all features
86+
uses: actions-rs/cargo@v1
87+
with:
88+
command: build
89+
args: --all-features
90+
env:
91+
RUSTFLAGS: "-C target-feature=+avx2 --deny warnings"
92+
- name: Clippy all features
93+
uses: actions-rs/clippy-check@v1
94+
with:
95+
token: ${{ secrets.GITHUB_TOKEN }}
96+
args: --all-features -- --deny warnings
97+
env:
98+
RUSTFLAGS: "-C target-feature=+avx2"
99+
100+
clippy-nightly:
101+
name: Clippy (nightly)
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v3
105+
- name: Rustup nightly toolchain
106+
uses: actions-rs/toolchain@v1
107+
with:
108+
toolchain: nightly
109+
components: clippy
110+
override: true
111+
default: true
112+
- name: Build all features
113+
uses: actions-rs/cargo@v1
114+
with:
115+
command: build
116+
args: --all-features
117+
env:
118+
RUSTFLAGS: "-C target-feature=+avx2 --deny warnings"
119+
- name: Clippy all features
120+
uses: actions-rs/clippy-check@v1
121+
with:
122+
token: ${{ secrets.GITHUB_TOKEN }}
123+
args: --all-features -- --deny warnings
124+
env:
125+
RUSTFLAGS: "-C target-feature=+avx2"
126+
127+
docs:
128+
name: Documentation
129+
runs-on: ubuntu-latest
130+
steps:
131+
- uses: actions/checkout@v3
132+
- name: Rustup nightly toolchain
133+
uses: actions-rs/toolchain@v1
134+
with:
135+
toolchain: nightly
136+
override: true
137+
default: true
138+
- name: cargo doc
139+
uses: actions-rs/cargo@v1
140+
with:
141+
command: doc
142+
args: --all-features --no-deps
143+
env:
144+
RUSTFLAGS: "-C target-feature=+avx2"
145+
RUSTDOCFLAGS: "-Dwarnings --cfg docsrs"
146+
147+
format:
148+
name: Format
149+
runs-on: ubuntu-latest
150+
steps:
151+
- uses: actions/checkout@v3
152+
- name: Rustup stable toolchain
153+
uses: actions-rs/toolchain@v1
154+
with:
155+
toolchain: stable
156+
components: rustfmt
157+
override: true
158+
default: true
159+
- name: Format
160+
uses: actions-rs/cargo@v1
161+
with:
162+
command: fmt
163+
args: --all -- --check

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/target
2+
/Cargo.lock
3+
4+
# Generated automatically.
5+
CHANGELOG.md

Cargo.toml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "align"
3+
version = "0.1.0"
4+
authors = ["Mateusz Gienieczko <mat@gienieczko.com>"]
5+
edition = "2021"
6+
description = "Utilities for alignment guarantees for data."
7+
readme = "./README.md"
8+
license = "MIT"
9+
keywords = ["alignment", "byte", "bytes", "block", "blocks"]
10+
categories = ["memory-management", "rust-patterns"]
11+
repository = "https://github.com/V0ldek/align"
12+
13+
[package.metadata.docs.rs]
14+
rustdoc-args = ["--cfg", "docsrs"]
15+
16+
[dependencies]
17+
cfg-if = "1.0.0"
18+
lazy_static = "1.4.0"
19+
page_size = "0.4.2"
20+
21+
[dev-dependencies]
22+
cargo-all-features = "1.7.0"
23+
24+
[features]
25+
default = ["simd"]
26+
simd = []
27+
28+
[profile.dev]
29+
lto = false
30+
31+
[profile.release]
32+
lto = "thin"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# `align` -- strongly typed memory alignment guarantees

0 commit comments

Comments
 (0)