Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-generate src/tables.rs: Rm all build-deps & build.rs #8

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,18 @@ jobs:
toolchain: stable
profile: minimal
override: true

- name: Configure src/tables.rs cache
id: cache-tables
uses: actions/cache@v3
with:
path: src/tables.rs
key: ${{ hashFiles('LineBreak.txt', 'gen-tables/**') }}

- name: Generates src/tables.rs
run: cargo run
working-directory: ./gen-tables
if: steps.cache-tables.outputs.cache-hit != 'true'

- name: Run tests
run: cargo test
run: cargo test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/Cargo.lock
/src/tables.rs
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ readme = "README.md"
keywords = ["unicode", "text", "layout"]
categories = ["internationalization"]
license = "Apache-2.0"
include = ["src/**/*", "build.rs", "LineBreak.txt", "LICENSE"]
include = ["src/**/*", "LICENSE"]
edition = "2021"
rust-version = "1.56"

[build-dependencies]
regex = "1"
hashbrown = "0.12.3"
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ assert!(linebreaks(text).eq([
]));
```

## Development

After cloning the repository or modifying `LineBreak.txt` the tables
have to be (re-)generated:

```sh
# Generate src/tables.rs
(cd gen-tables && cargo run)
# Run tests to make sure it was successful
cargo test
```

[UAX14]: https://www.unicode.org/reports/tr14/
1 change: 1 addition & 0 deletions gen-tables/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
100 changes: 100 additions & 0 deletions gen-tables/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions gen-tables/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "gen-tables"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
regex = "1"
hashbrown = "0.14"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
16 changes: 7 additions & 9 deletions build.rs → gen-tables/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ use std::hash::{BuildHasher, Hash, Hasher};
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::marker::PhantomData;
use std::ops::Range;
use std::path::Path;
use std::str::FromStr;
use std::{env, error, iter};
use std::{error, iter};

include!("src/shared.rs");
include!("../../src/shared.rs");

impl FromStr for BreakClass {
type Err = &'static str;
Expand Down Expand Up @@ -88,6 +87,7 @@ static BREAK_CLASS_TABLE: [&str; NUM_CLASSES] = [

#[derive(Copy, Clone)]
#[repr(u8)]
#[allow(clippy::upper_case_acronyms)]
enum ExtraState {
ZWSP = sot + 1,
OPSP,
Expand Down Expand Up @@ -683,8 +683,8 @@ struct CpTrie<T> {
}

fn main() -> Result<(), Box<dyn error::Error>> {
println!("cargo:rerun-if-changed=LineBreak.txt");
debug_assert!(NUM_STATES <= 0x3F, "too many states");
#[allow(clippy::assertions_on_constants)]
const _: () = debug_assert!(NUM_STATES <= 0x3F, "too many states");

let pair_table = rules2table! {
// Non-tailorable Line Breaking Rules
Expand Down Expand Up @@ -795,7 +795,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
;
(?P<lb>\w{2,3}) # Line_Break property",
)?;
let prop_ranges = BufReader::new(File::open("LineBreak.txt")?)
let prop_ranges = BufReader::new(File::open("../LineBreak.txt")?)
.lines()
.map(Result::unwrap)
.filter(|l| !(l.starts_with('#') || l.is_empty()))
Expand Down Expand Up @@ -828,9 +828,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
builder.build()
};

let out_dir = env::var("OUT_DIR")?;
let dest_path = Path::new(&out_dir).join("tables.rs");
let mut stream = BufWriter::new(File::create(&dest_path)?);
let mut stream = BufWriter::new(File::create("../src/tables.rs")?);
writeln!(
stream,
"const BREAK_PROP_TRIE_HIGH_START: u32 = {};
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use core::iter::once;
pub const UNICODE_VERSION: (u8, u8, u8) = (15, 0, 0);

include!("shared.rs");

include!(concat!(env!("OUT_DIR"), "/tables.rs"));
include!("tables.rs");

/// Returns the line break property of the specified code point.
///
Expand Down
Loading