diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rust/cargo/README.md | 45 | ||||
-rw-r--r-- | src/rust/cargo/circle/Cargo.lock | 75 | ||||
-rw-r--r-- | src/rust/cargo/circle/Cargo.toml | 7 | ||||
-rw-r--r-- | src/rust/cargo/circle/TARGETS | 15 | ||||
-rw-r--r-- | src/rust/cargo/circle/src/main.rs | 18 |
5 files changed, 160 insertions, 0 deletions
diff --git a/src/rust/cargo/README.md b/src/rust/cargo/README.md new file mode 100644 index 0000000..5ac8e27 --- /dev/null +++ b/src/rust/cargo/README.md @@ -0,0 +1,45 @@ +# Importing cargo dependencies + +The [rules for rust](https://github.com/just-buildsystem/rules-rust) also +bring a tool to import dependencies from cargo. Here we give an overview of +its usage, using the subidrectory `circle` as a dependency. + +## Files written by hand + +Cargo dependencies are described as dependencies of a crate. So all the +files you would normally write by hand when writing a crate have to be +manually added. As we define a binary, those are + - `Cargo.toml`, and + - `src/main.rs`. + +## Using `just-import-cargo` + +As other import tools, `just-import-cargo` expects a repository specification +on standard input and returns one on standard output. It needs to know + - the root of the pyhsical repository, and + - the location of the crate directory, relative to the root of the physical + repository. + - the name of the already imported `rules-rust` repository. + +While the tool in general can also import `rules-rust` itself, we need to import +the rules manually first, as we have to provide our own target root for the +defaults. Future versions of the rules might bring a defaults target suitable +for our use case, but so far this is not the case. + +The name of the imported main repository is the crate name (without version), +as specified in the `Cargo.toml` file. Some care should be taken that is does +not conflict with already existing repositories; repositories from the +`etc/repos.templace.json` can have a binding to that still to be imported +repository, as usual. + +As opposed to other import tools, however, `just-import-cargo` also creates +files in the pysical repository. Those are the following. + - In the crate the file `Cargo.lock` generated by the call to cargo, as + well as a target file, + - The file `etc/defaults/rust/TARGETS` relative to in the top-level of the + physical repository (with a content independent of the respective crate). + This file is the reason that our `rules-rust/nix` use `nix.TARGETS` as + target-file name. + - In the directory `etc/deps-rust` target files for all the imported crates. + As their name encode crate name and version, calling `just-import-cargo` + for several crates should not cause a conflict here. diff --git a/src/rust/cargo/circle/Cargo.lock b/src/rust/cargo/circle/Cargo.lock new file mode 100644 index 0000000..9b1bff2 --- /dev/null +++ b/src/rust/cargo/circle/Cargo.lock @@ -0,0 +1,75 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "circle_sampling" +version = "0.1.0" +dependencies = [ + "rand", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/src/rust/cargo/circle/Cargo.toml b/src/rust/cargo/circle/Cargo.toml new file mode 100644 index 0000000..563be5e --- /dev/null +++ b/src/rust/cargo/circle/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "circle_sampling" +version = "0.1.0" +edition = "2021" + +[dependencies] +rand = "0.8.5" diff --git a/src/rust/cargo/circle/TARGETS b/src/rust/cargo/circle/TARGETS new file mode 100644 index 0000000..9085e22 --- /dev/null +++ b/src/rust/cargo/circle/TARGETS @@ -0,0 +1,15 @@ +{ "circle_sampling": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["circle_sampling"] + , "crate_root": ["src/main.rs"] + , "srcs": ["src/main.rs"] + , "edition": ["2021"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [["@", "rand", "", "rand"]] + , "cargo_features": [] + , "stage": ["circle_sampling-0.1.0"] + , "version": ["0", "1", "0"] + , "pkg_name": ["circle_sampling"] + } +} diff --git a/src/rust/cargo/circle/src/main.rs b/src/rust/cargo/circle/src/main.rs new file mode 100644 index 0000000..329542f --- /dev/null +++ b/src/rust/cargo/circle/src/main.rs @@ -0,0 +1,18 @@ +use rand::Rng; + +fn main() { + let mut x :i16; + let mut y :i16; + let mut rng = rand::thread_rng(); + + loop { + x = rng.gen_range(-100..=100); + y = rng.gen_range(-100..=100); + + if x*x + y*y < 100*100 { + break; + } + } + + println!("{x} {y}") +} |