Skip to content

Commit 4ec87bd

Browse files
committed
champion.rs build.rs proof of concept
conditional compilation optional `autoupdate` feature use feature instead of cfg to avoid recompiling everything wip fix include models/spec wip generate models.rs store generated rust in git update autogen feature deps grab specs from online fixes route everything except endpoints now cleanup codegen preserve schema map order cleanup meta.rs final codegen in build.rs cleanup endpoints codegen build and docs tidying document build info for clippy cfgs actually working now, oops cleanup bare urls for rustdoc newtype enum fix rephrase docs
1 parent aa74790 commit 4ec87bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+15308
-4907
lines changed

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[build]
2+
rustflags = [ "--cfg", "riven_autogen" ]
3+
14
[env]
25
RUST_BACKTRACE = "full"
36
RUST_LOG = "info,riven=debug"
7+
RIVEN_AUTOGEN_DEVMODE = "none"

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
/target
2-
**/*.rs.bk
32
/doc
4-
apikey.txt
5-
3+
/apikey.txt

Cargo.lock

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ instance, setting the desired config values, and passing that to [`RiotApi::new`
146146
(instead of just the API key). For example, you can configure the number of
147147
times Riven retries using [`RiotApiConfig::set_retries(...)`](https://docs.rs/riven/latest/riven/struct.RiotApiConfig.html#method.set_retries).
148148

149-
150149
## Semantic Versioning
151150

152151
This package follows semantic versioning to an extent. However, the Riot API
@@ -165,24 +164,49 @@ version. (`major.minor.patch`)
165164
Parts of Riven that do not depend on Riot API changes do follow semantic
166165
versioning.
167166

167+
## Auto-Updating
168+
169+
Riven may be configured to automatically update its generated code from the latest version of the
170+
[riotapi-schema](https://github.com/MingweiSamuel/riotapi-schema). This requires an internet
171+
connection, violates semantic versioning, and may break your build. To enable auto-updating, set
172+
the `riven_autogen` cfg option for `rustc` (not a cargo feature).
173+
174+
If the build configuration doesn't change, then the generated code will be cached and not
175+
subsequently update. To change the build configuration and force an update you can set the
176+
`RIVEN_AUTOGEN_NONCE` environment variable to a new value.
177+
178+
For example, setting `RIVEN_AUTOGEN_NONCE` to the current date will trigger an update once a day,
179+
assuming the build configuration otherwise doesn't change:
180+
```bash
181+
RUSTFLAGS="--cfg riven_autogen" RIVEN_AUTOGEN_NONCE="$(date +%Y-%m-%d)" cargo build
182+
```
183+
168184
## Additional Help
169185

170186
Feel free to [make an issue](https://github.com/MingweiSamuel/Riven/issues/new)
171187
if you are have any questions or trouble with Riven.
172188

173189
# Development
174190

175-
NodeJS is used to generate code for Riven. The
176-
[`riven/srcgen`](https://github.com/MingweiSamuel/Riven/tree/v/2.x.x/riven/srcgen)
177-
folder contains the code and [doT.js](https://olado.github.io/doT/index.html)
178-
templates. `index.js` lists the JSON files downloaded and used to generate the
179-
code.
180-
181-
To set up the srcgen, you will first need to install NodeJS. Then enter the
182-
`riven/srcgen` folder and run `npm ci` (or `npm install`) to install
183-
dependencies.
184-
185-
To run the srcgen use `node riven/srcgen` from the repository root.
191+
Riven is a regular cargo package for the most part, and can be built directly from the repository
192+
source code without additional consideration. However source files with names matching `*.gen.rs`
193+
have been automatically generated by the `riven/build` build script. The build script is set up to
194+
be skipped by default; to actually update the generated files run `./srcgen.bash`.
195+
196+
## Build Script Configuration
197+
198+
The the `riven_autogen` cfg option (for `rustc`, not a cargo feature) enables the build script. If
199+
unset, the build script is not even compiled, which ensures fast builds when Riven is used as a
200+
dependency. If set, the build script will be compiled but the actual behavior depends on the
201+
`RIVEN_AUTOGEN_DEVMODE` environment variable. If unset or set to `"outdir"`, will behave as in the
202+
[auto-update](#auto-updating) section above, generating files to `OUT_DIR` to be used by Riven
203+
instead of the checked-in `src` files. If set to `"src"`, the build script will overwrite the files
204+
in `src` directly (this is what `./autogen_src.bash` does). If set to `"none"`, the build script
205+
will be built but will not generate any files. This is the default for the repository, set in
206+
`.cargo/config.toml`, to avoids extraneous updates.
207+
208+
The build script will not generally re-run after the initial build, unless the `RIVEN_AUTOGEN_NONCE`
209+
environment variable changes, or something else in the build configuration changes.
186210

187211
## Testing
188212

autogen_src.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
RIVEN_AUTOGEN_NONCE="$(date)" RIVEN_AUTOGEN_DEVMODE="src" cargo rustc -p riven

riven/Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ readme = "../README.md"
88
license = "MIT"
99
edition = "2018"
1010
rust-version = "1.71.1"
11-
include = [ "/src/**", "/../README.md" ]
11+
include = [ "/src", "/build", "/../README.md" ]
1212
keywords = [ "riot-games", "riot", "league", "league-of-legends" ]
1313
categories = [ "api-bindings", "web-programming::http-client", "wasm" ]
14+
build = "build/main.rs"
1415

1516
[lib]
1617
crate-type = [ "cdylib", "rlib" ]
@@ -58,6 +59,7 @@ eserde = { optional = true, version = "0.1.6", features = [ "json" ] }
5859
futures = "0.3.0"
5960
log = "0.4.8"
6061
memo-map = "0.3.0"
62+
macro_rules_attribute = "0.2.0"
6163
metrics = { optional = true, version = "0.24.0" }
6264
num_enum = "0.5.0"
6365
parking_lot = "0.12.0"
@@ -70,6 +72,7 @@ slab = "0.4.4"
7072
strum = "0.20.0"
7173
strum_macros = "0.20.0"
7274
tracing = { optional = true, version = "0.1.22" }
75+
web-time = { optional = true, version = "1.0.0" }
7376

7477
[target.'cfg(not(target_family = "wasm"))'.dependencies]
7578
tokio = { version = "1.20.0", default-features = false, features = [ "time" ] }
@@ -95,6 +98,19 @@ console_log = "1.0"
9598
wasm-bindgen = "0.2.70"
9699
wasm-bindgen-test = "0.3"
97100

101+
[target.'cfg(riven_autogen)'.build-dependencies]
102+
heck = "0.5.0"
103+
indexmap = { version = "2.0.0", features = [ "serde" ] }
104+
prettyplease = "0.2.30"
105+
proc-macro2 = "1.0.93"
106+
quote = "1.0.38"
107+
reqwest = { version = "0.11.2", default-features = false, features = [ "gzip" ] }
108+
serde = { version = "1.0.85", features = [ "derive" ] }
109+
serde_derive = "1.0.85"
110+
serde_json = "1.0.1"
111+
syn = "2.0.96"
112+
tokio = { version = "1.20.0", default-features = false, features = [ "rt", "sync" ] }
113+
98114
[target.'cfg(docsrs_deps)'.dependencies]
99115
eserde = { version = "0.1.6", features = [ "json" ] }
100116
gloo-timers = { version = "0.3", features = [ "futures" ] }

0 commit comments

Comments
 (0)