You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/1_5/tutorials/cargo.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
title: Configuring Cargo.toml
3
3
---
4
4
5
+
6
+
5
7
ICU4X makes heavy use of small crates and Cargo features in order to be highly modular. This tutorial is intended to help you set up a Cargo.toml file to download what you need for ICU4X.
6
8
7
9
## Basic Cargo.toml with compiled data
@@ -15,29 +17,33 @@ icu = "1.5"
15
17
16
18
In your main.rs, you can use all stable ICU4X components for the recommended set of locales, which get compiled into the library.
17
19
20
+
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/default)
18
21
19
22
## Cargo.toml with custom compiled data
20
23
21
24
If you wish to use custom compiled data for ICU4X, no changes to Cargo.toml are required. Instead, set the `ICU4X_DATA_DIR` environment variable to the
22
25
datagen output during your build:
23
26
24
27
```command
25
-
icu4x-datagen --format baked --markers all --locales ru --out baked_data
28
+
icu4x-datagen --format mod --keys all --locales ru --out baked_data
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/custom_compiled)
29
33
30
34
## Cargo.toml with experimental modules
31
35
32
36
Experimental modules are published in a separate `icu_experimental` crate:
33
37
34
38
```toml
35
39
[dependencies]
36
-
icu = { version = "1.5", features = ["experimental"] }
40
+
icu = "1.5"
41
+
icu_experimental = "0"
37
42
```
38
43
39
44
In your main.rs, you can now use e.g. the `icu_experimental::displaynames` module.
40
45
46
+
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/experimental)
41
47
42
48
## Cargo.toml with Buffer Provider
43
49
@@ -49,8 +55,9 @@ icu = { version = "1.5", features = ["serde"] }
49
55
icu_provider_blob = "1.5"
50
56
```
51
57
52
-
To learn about building ICU4X data, including whether to check in the data blob file to your repository, see [Data management](/icu4x-docs/1_5/tutorials/data-management).
58
+
To learn about building ICU4X data, including whether to check in the data blob file to your repository, see [data-management.md](/icu4x-docs/1_5/tutorials/./data-management).
53
59
60
+
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/buffer)
54
61
55
62
## Cargo.toml with `Sync`
56
63
@@ -63,6 +70,7 @@ icu = { version = "1.5", features = ["sync"] }
63
70
64
71
You can now use most ICU4X types when `Send + Sync` are required, such as when sharing across threads.
65
72
73
+
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/sync)
66
74
67
75
## Cargo.toml with `build.rs` data generation
68
76
@@ -72,20 +80,20 @@ If you wish to use data generation in a `build.rs` script, you need to manually
72
80
[dependencies]
73
81
icu = { version = "1.5", default-features = false } # turn off compiled_data
74
82
icu_provider = "1.5"# for databake
75
-
icu_provider_baked = "1.5"# for databake
76
83
zerovec = "0.9"# for databake
77
84
78
85
# for build.rs:
79
86
[build-dependencies]
80
87
icu = "1.5"
81
-
icu_provider_export = "1.5"
82
-
icu_provider_source = "1.5"
88
+
icu_datagen = "1.5"
83
89
```
84
90
85
-
This example has an additional section for auto-generating the data in build.rs. In your build.rs, invoke the ICU4X Datagen API with the set of markers you require. Don't worry; if using databake, you will get a compiler error if you don't specify enough markers.
91
+
This example has an additional section for auto-generating the data in build.rs. In your build.rs, invoke the ICU4X Datagen API with the set of keys you require. Don't worry; if using databake, you will get a compiler error if you don't specify enough keys.
86
92
87
93
The build.rs approach has several downsides and should only be used if Cargo is the only build system you can use, and you cannot check in your data:
88
-
* The build script with the whole of `icu_provider_source` in it is slow to build
89
-
* If you're using networking features of `icu_provider_source` (behind the `networking` Cargo feature), the build script will access the network
90
-
* Using the data requires ICU4X's [`_unstable`](https://docs.rs/icu_provider/latest/icu_provider/constructors/index.html) APIs with a custom data provider, and that `icu_provider_source` is the same *minor* version as the `icu` crate.
94
+
* The build script with the whole of `icu_datagen` in it is slow to build
95
+
* If you're using networking features of `icu_datagen` (behind the `networking` Cargo feature), the build script will access the network
96
+
* Using the data requires ICU4X's [`_unstable`](https://docs.rs/icu_provider/latest/icu_provider/constructors/index.html) APIs with a custom data provider, and that `icu_datagen` is the same *minor* version as the `icu` crate.
91
97
*`build.rs` output is not written to the console so it will appear that the build is hanging
98
+
99
+
[« Fully Working Example »](https://github.com/unicode-org/icu4x/tree/release%2F1.5/tutorials/./crates/baked)
0 commit comments