Skip to content

Commit a4e95f4

Browse files
Add target os section to typeshare book
1 parent ea419f4 commit a4e95f4

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

docs/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[book]
2-
authors = ["Jane Lewis", "Josh Rampersad"]
2+
authors = ["Jane Lewis", "Josh Rampersad", "Darrell Roberts"]
33
language = "en"
44
multilingual = false
55
src = "src"

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
- [Usage](./usage/usage.md)
66
- [Annotations](./usage/annotations.md)
77
- [Configuration](./usage/configuration.md)
8+
- [Target OS](./usage/target_os.md)
89
- [Contributing](./contributing.md)

docs/src/usage/target_os.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Target OS
2+
3+
The `--target-os` argument is an optional command line argument that allows you to specify a list of comma separated `target_os` values. In your
4+
Rust source code you can use the [`target_os`](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os) attribute
5+
to restrict a type, variant or fields.
6+
7+
If you do not use `--target-os` then typeshare will generate all types, variants and fields that are typeshared.
8+
9+
## Example
10+
```
11+
./typeshare ./my_rust_project \
12+
--lang=typescript \
13+
--output-file=my_typescript_definitions.ts \
14+
--target-os=linux,macos
15+
```
16+
17+
The example above is stating any types, variants, fields that are typeshared and are not applicable for `linux` or `macos` will be omitted from
18+
typeshare type generation.
19+
20+
## Supported `target_os` definitions.
21+
22+
### Simple standalone.
23+
24+
```rust
25+
#[cfg(target_os = "android")]
26+
pub struct MyType;
27+
```
28+
29+
This type will only be generated if `--target-os` has `android` in the list of target_os values.
30+
31+
### Simple not rule
32+
33+
```rust
34+
#[cfg(not(target_os = "android"))]
35+
pub struct MyType;
36+
```
37+
This type will only be generated if `--target-os` does not include `android` in the list of target_os values.
38+
39+
### Multiple not any rule
40+
41+
```rust
42+
#[cfg(not(any(target_os = "android", target_os = "ios")))]
43+
pub struct MyType;
44+
```
45+
46+
This type will only be generated if `--target-os` does not include `android` or `ios` in the list of target_os values.
47+
48+
The following example will allow `MyType` to be typeshared.
49+
```
50+
./typeshare ./my_rust_project \
51+
--lang=typescript \
52+
--output-file=my_typescript_definitions.ts \
53+
--target-os=linux,macos
54+
```
55+
56+
The following example will not allow `MyType` to be typeshared.
57+
```
58+
./typeshare ./my_rust_project \
59+
--lang=typescript \
60+
--output-file=my_typescript_definitions.ts \
61+
--target-os=android,macos
62+
```
63+
64+
## Combined with features or other cfg attributes
65+
66+
Typehsare will not take into consideration any other `cfg` attributes other than `target_os` when generating types.
67+
68+
For example:
69+
70+
```rust
71+
#[cfg(any(target_os = "android", feature = "android-test")]
72+
pub struct MyType;
73+
```
74+
75+
```rust
76+
#[cfg(all(target_os = "android", feature = "android-test")]
77+
pub struct MyType;
78+
```
79+
80+
```
81+
./typeshare ./my_rust_project \
82+
--lang=typescript \
83+
--output-file=my_typescript_definitions.ts \
84+
--target-os=android
85+
```
86+
87+
In both examples above, `MyType` will be typeshared.

0 commit comments

Comments
 (0)