-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build.rs for glob all yaml files for cargo build cache.
- Loading branch information
Showing
4 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[package] | ||
authors = ["Jason Lee <[email protected]>"] | ||
build = "build.rs" | ||
categories = ["localization", "internationalization"] | ||
description = "Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts." | ||
edition = "2018" | ||
|
@@ -9,11 +10,15 @@ license = "MIT" | |
name = "rust-i18n" | ||
readme = "README.md" | ||
repository = "https://github.com/longbridgeapp/rust-i18n" | ||
version = "0.2.1-alpha.0" | ||
version = "0.2.1" | ||
|
||
[dependencies] | ||
lazy_static = "1.4.0" | ||
rust-i18n-support = {path = "./crates/support", version = "0.2"} | ||
|
||
[dev-dependencies] | ||
foo = {path = "examples/foo"} | ||
|
||
[build-dependencies] | ||
glob = "0.3" | ||
regex = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// https://github.com/longbridgeapp/rust-i18n/blob/v0.1.6/crates/support/src/lib.rs#L9 | ||
fn workdir(dest: &str) -> String { | ||
let seperator = regex::Regex::new(r"(/target/(.+?)/build/)|(\\target\\(.+?)\\build\\)") | ||
.expect("Invalid regex"); | ||
let parts = seperator.split(dest).collect::<Vec<_>>(); | ||
|
||
if parts.len() < 2 { | ||
panic!("Parse workdir error, {} not correct.", dest); | ||
} | ||
|
||
parts[0].to_string() | ||
} | ||
|
||
fn find_all_yaml_for_cargo_cache() { | ||
let dest = std::env::var("OUT_DIR").expect("OUT_DIR env not found"); | ||
let workdir = workdir(&dest); | ||
let locale_path = format!("{}/**/locales/**/*.yml", workdir); | ||
|
||
for entry in glob::glob(&locale_path).expect("Failed to read glob pattern") { | ||
let entry = entry.unwrap(); | ||
println!("cargo:rerun-if-changed={}", entry.display()); | ||
} | ||
} | ||
|
||
fn main() { | ||
find_all_yaml_for_cargo_cache(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters