Skip to content
Open
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
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build]
rustflags = [ "--cfg", "riven_autogen" ]

[env]
RUST_BACKTRACE = "full"
RUST_LOG = "info,riven=debug"
RIVEN_AUTOGEN_DEVMODE = "none"
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/target
**/*.rs.bk
/doc
apikey.txt

/apikey.txt
48 changes: 47 additions & 1 deletion Cargo.lock

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

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


## Semantic Versioning

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

## Auto-Updating

Riven may be configured to automatically update its generated code from the latest version of the
[riotapi-schema](https://github.com/MingweiSamuel/riotapi-schema). This requires an internet
connection, violates semantic versioning, and may break your build. To enable auto-updating, set
the `riven_autogen` cfg option for `rustc` (not a cargo feature).

If the build configuration doesn't change, then the generated code will be cached and not
subsequently update. To change the build configuration and force an update you can set the
`RIVEN_AUTOGEN_NONCE` environment variable to a new value.

For example, setting `RIVEN_AUTOGEN_NONCE` to the current date will trigger an update once a day,
assuming the build configuration otherwise doesn't change:
```bash
RUSTFLAGS="--cfg riven_autogen" RIVEN_AUTOGEN_NONCE="$(date +%Y-%m-%d)" cargo build
```

## Additional Help

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

# Development

NodeJS is used to generate code for Riven. The
[`riven/srcgen`](https://github.com/MingweiSamuel/Riven/tree/v/2.x.x/riven/srcgen)
folder contains the code and [doT.js](https://olado.github.io/doT/index.html)
templates. `index.js` lists the JSON files downloaded and used to generate the
code.

To set up the srcgen, you will first need to install NodeJS. Then enter the
`riven/srcgen` folder and run `npm ci` (or `npm install`) to install
dependencies.

To run the srcgen use `node riven/srcgen` from the repository root.
Riven is a regular cargo package for the most part, and can be built directly from the repository
source code without additional consideration. However source files with names matching `*.gen.rs`
have been automatically generated by the `riven/build` build script. The build script is set up to
be skipped by default; to actually update the generated files run `./srcgen.bash`.

## Build Script Configuration

The the `riven_autogen` cfg option (for `rustc`, not a cargo feature) enables the build script. If
unset, the build script is not even compiled, which ensures fast builds when Riven is used as a
dependency. If set, the build script will be compiled but the actual behavior depends on the
`RIVEN_AUTOGEN_DEVMODE` environment variable. If unset or set to `"outdir"`, will behave as in the
[auto-update](#auto-updating) section above, generating files to `OUT_DIR` to be used by Riven
instead of the checked-in `src` files. If set to `"src"`, the build script will overwrite the files
in `src` directly (this is what `./autogen_src.bash` does). If set to `"none"`, the build script
will be built but will not generate any files. This is the default for the repository, set in
`.cargo/config.toml`, to avoids extraneous updates.

The build script will not generally re-run after the initial build, unless the `RIVEN_AUTOGEN_NONCE`
environment variable changes, or something else in the build configuration changes.

## Testing

Expand Down
4 changes: 4 additions & 0 deletions autogen_src.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euxo pipefail

RIVEN_AUTOGEN_NONCE="$(date)" RIVEN_AUTOGEN_DEVMODE="src" cargo rustc -p riven
17 changes: 16 additions & 1 deletion riven/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ readme = "../README.md"
license = "MIT"
edition = "2018"
rust-version = "1.71.1"
include = [ "/src/**", "/../README.md" ]
include = [ "/src", "/build", "/../README.md" ]
keywords = [ "riot-games", "riot", "league", "league-of-legends" ]
categories = [ "api-bindings", "web-programming::http-client", "wasm" ]
build = "build/main.rs"

[lib]
crate-type = [ "cdylib", "rlib" ]
Expand Down Expand Up @@ -58,6 +59,7 @@ eserde = { optional = true, version = "0.1.6", features = [ "json" ] }
futures = "0.3.0"
log = "0.4.8"
memo-map = "0.3.0"
macro_rules_attribute = "0.2.0"
metrics = { optional = true, version = "0.24.0" }
num_enum = "0.5.0"
parking_lot = "0.12.0"
Expand Down Expand Up @@ -95,6 +97,19 @@ console_log = "1.0"
wasm-bindgen = "0.2.70"
wasm-bindgen-test = "0.3"

[target.'cfg(riven_autogen)'.build-dependencies]
heck = "0.5.0"
indexmap = { version = "2.0.0", features = [ "serde" ] }
prettyplease = "0.2.30"
proc-macro2 = "1.0.93"
quote = "1.0.38"
reqwest = { version = "0.11.2", default-features = false, features = [ "gzip" ] }
serde = { version = "1.0.85", features = [ "derive" ] }
serde_derive = "1.0.85"
serde_json = "1.0.1"
syn = "2.0.96"
tokio = { version = "1.20.0", default-features = false, features = [ "rt", "sync" ] }

[target.'cfg(docsrs_deps)'.dependencies]
eserde = { version = "0.1.6", features = [ "json" ] }
gloo-timers = { version = "0.3", features = [ "futures" ] }
Expand Down
Loading