diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-06-27 12:25:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 12:25:35 +0200 |
commit | 05b2d6fc51146fe07340a58bc87fbbd99e788143 (patch) | |
tree | 2c607815866fdb7887dc5486255d2a7729f23578 | |
parent | 7dc9a7b9107b2607e9870d7fc92fb2d40505f7ef (diff) | |
parent | c6b35f8f2e83621b4e53ab999e5b5bf146a73aa0 (diff) | |
download | hello-nix-05b2d6fc51146fe07340a58bc87fbbd99e788143.tar.gz |
Merge pull request #3 from aehlig/cargo-example
Add example on how to use cargo
26 files changed, 940 insertions, 47 deletions
@@ -117,6 +117,9 @@ There are two files pinning dependencies calls [etc/generate-repos.sh](./etc/generate-repos.sh) in our `nix-shell`, which also brings in tools required for this step. +Specific considerations + - [cargo](./src/rust/cargo/README.md) + ### Logical repositories This project uses several logical repositories. diff --git a/etc/defaults/rust/TARGETS b/etc/defaults/rust/TARGETS index fbd1a69..fe4de0a 100644 --- a/etc/defaults/rust/TARGETS +++ b/etc/defaults/rust/TARGETS @@ -1,43 +1,3 @@ { "defaults": - { "type": "configure" - , "target": "defaults (unconfigured)" - , "arguments_config": ["TOOLCHAIN_CONFIG"] - , "config": - { "type": "let*" - , "bindings": - [ [ "toolchain" - , { "type": "lookup" - , "map": - { "type": "var" - , "name": "TOOLCHAIN_CONFIG" - , "default": {"type": "empty_map"} - } - , "key": "RUST" - , "default": {"type": "empty_map"} - } - ] - , [ "RUSTC" - , { "type": "lookup" - , "map": {"type": "var", "name": "toolchain"} - , "key": "RUSTC" - , "default": "rustc" - } - ] - , [ "PATH" - , { "type": "lookup" - , "map": {"type": "var", "name": "toolchain"} - , "key": "PATH" - , "default": [] - } - ] - ] - , "body": {"type": "env", "vars": ["RUSTC", "PATH"]} - } - } -, "defaults (unconfigured)": - { "type": "defaults" - , "arguments_config": ["RUSTC", "PATH"] - , "RUSTC": [{"type": "var", "name": "RUSTC"}] - , "PATH": {"type": "var", "name": "PATH"} - } + {"type": "defaults", "base": [["@", "orig-rules", "rust", "defaults"]]} } diff --git a/etc/defaults/rust/nix.TARGETS b/etc/defaults/rust/nix.TARGETS new file mode 100644 index 0000000..fbd1a69 --- /dev/null +++ b/etc/defaults/rust/nix.TARGETS @@ -0,0 +1,43 @@ +{ "defaults": + { "type": "configure" + , "target": "defaults (unconfigured)" + , "arguments_config": ["TOOLCHAIN_CONFIG"] + , "config": + { "type": "let*" + , "bindings": + [ [ "toolchain" + , { "type": "lookup" + , "map": + { "type": "var" + , "name": "TOOLCHAIN_CONFIG" + , "default": {"type": "empty_map"} + } + , "key": "RUST" + , "default": {"type": "empty_map"} + } + ] + , [ "RUSTC" + , { "type": "lookup" + , "map": {"type": "var", "name": "toolchain"} + , "key": "RUSTC" + , "default": "rustc" + } + ] + , [ "PATH" + , { "type": "lookup" + , "map": {"type": "var", "name": "toolchain"} + , "key": "PATH" + , "default": [] + } + ] + ] + , "body": {"type": "env", "vars": ["RUSTC", "PATH"]} + } + } +, "defaults (unconfigured)": + { "type": "defaults" + , "arguments_config": ["RUSTC", "PATH"] + , "RUSTC": [{"type": "var", "name": "RUSTC"}] + , "PATH": {"type": "var", "name": "PATH"} + } +} diff --git a/etc/deps-rust/TARGETS.cfg-if-1.0.0 b/etc/deps-rust/TARGETS.cfg-if-1.0.0 new file mode 100644 index 0000000..2faaaaf --- /dev/null +++ b/etc/deps-rust/TARGETS.cfg-if-1.0.0 @@ -0,0 +1,26 @@ +{ "cfg_if": + { "type": "export" + , "target": "cfg_if-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "cfg_if-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["cfg_if"] + , "crate_root": ["src/lib.rs"] + , "srcs": ["src/lib.rs"] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [] + , "cargo_features": [] + , "stage": ["cfg-if-1.0.0"] + , "version": ["1", "0", "0"] + , "pkg_name": ["cfg-if"] + } +, "compiler_builtins": + {"type": ["@", "rules", "cargo", "feature"], "name": ["compiler_builtins"]} +, "core": {"type": ["@", "rules", "cargo", "feature"], "name": ["core"]} +, "rustc-dep-of-std": + {"type": ["@", "rules", "cargo", "feature"], "name": ["rustc-dep-of-std"]} +} diff --git a/etc/deps-rust/TARGETS.getrandom-0.2.15 b/etc/deps-rust/TARGETS.getrandom-0.2.15 new file mode 100644 index 0000000..c36da18 --- /dev/null +++ b/etc/deps-rust/TARGETS.getrandom-0.2.15 @@ -0,0 +1,64 @@ +{ "getrandom": + { "type": "export" + , "target": "getrandom-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "getrandom-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["getrandom"] + , "crate_root": ["src/lib.rs"] + , "srcs": + [ "src/linux_android_with_fallback.rs" + , "src/fuchsia.rs" + , "src/windows.rs" + , "src/custom.rs" + , "src/vxworks.rs" + , "src/util.rs" + , "src/espidf.rs" + , "src/solid.rs" + , "src/use_file.rs" + , "src/error_impls.rs" + , "src/apple-other.rs" + , "src/js.rs" + , "src/getentropy.rs" + , "src/solaris.rs" + , "src/hermit.rs" + , "src/linux_android.rs" + , "src/error.rs" + , "src/lazy.rs" + , "src/wasi.rs" + , "src/netbsd.rs" + , "src/rdrand.rs" + , "src/getrandom.rs" + , "src/lib.rs" + , "src/util_libc.rs" + ] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [["@", "cfg-if", "", "cfg_if"], ["@", "libc", "", "libc"]] + , "cargo_features": ["std"] + , "stage": ["getrandom-0.2.15"] + , "version": ["0", "2", "15"] + , "pkg_name": ["getrandom"] + } +, "compiler_builtins": + {"type": ["@", "rules", "cargo", "feature"], "name": ["compiler_builtins"]} +, "core": {"type": ["@", "rules", "cargo", "feature"], "name": ["core"]} +, "custom": {"type": ["@", "rules", "cargo", "feature"], "name": ["custom"]} +, "js": {"type": ["@", "rules", "cargo", "feature"], "name": ["js"]} +, "js-sys": {"type": ["@", "rules", "cargo", "feature"], "name": ["js-sys"]} +, "linux_disable_fallback": + { "type": ["@", "rules", "cargo", "feature"] + , "name": ["linux_disable_fallback"] + } +, "rdrand": {"type": ["@", "rules", "cargo", "feature"], "name": ["rdrand"]} +, "rustc-dep-of-std": + {"type": ["@", "rules", "cargo", "feature"], "name": ["rustc-dep-of-std"]} +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +, "test-in-browser": + {"type": ["@", "rules", "cargo", "feature"], "name": ["test-in-browser"]} +, "wasm-bindgen": + {"type": ["@", "rules", "cargo", "feature"], "name": ["wasm-bindgen"]} +} diff --git a/etc/deps-rust/TARGETS.libc-0.2.155 b/etc/deps-rust/TARGETS.libc-0.2.155 new file mode 100644 index 0000000..2aa9d20 --- /dev/null +++ b/etc/deps-rust/TARGETS.libc-0.2.155 @@ -0,0 +1,287 @@ +{ "libc": + { "type": "export" + , "target": "libc-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "libc-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["libc"] + , "crate_root": ["src/lib.rs"] + , "srcs": + [ "build.rs" + , "src/fixed_width_ints.rs" + , "src/switch.rs" + , "src/xous.rs" + , "src/sgx.rs" + , "src/macros.rs" + , "src/wasi.rs" + , "src/lib.rs" + , "src/psp.rs" + , "src/solid/aarch64.rs" + , "src/solid/mod.rs" + , "src/solid/arm.rs" + , "src/fuchsia/aarch64.rs" + , "src/fuchsia/riscv64.rs" + , "src/fuchsia/no_align.rs" + , "src/fuchsia/align.rs" + , "src/fuchsia/x86_64.rs" + , "src/fuchsia/mod.rs" + , "src/unix/no_align.rs" + , "src/unix/align.rs" + , "src/unix/mod.rs" + , "src/unix/haiku/b64.rs" + , "src/unix/haiku/x86_64.rs" + , "src/unix/haiku/b32.rs" + , "src/unix/haiku/mod.rs" + , "src/unix/haiku/native.rs" + , "src/unix/nto/aarch64.rs" + , "src/unix/nto/x86_64.rs" + , "src/unix/nto/neutrino.rs" + , "src/unix/nto/mod.rs" + , "src/unix/newlib/no_align.rs" + , "src/unix/newlib/align.rs" + , "src/unix/newlib/generic.rs" + , "src/unix/newlib/mod.rs" + , "src/unix/newlib/aarch64/mod.rs" + , "src/unix/newlib/arm/mod.rs" + , "src/unix/newlib/vita/mod.rs" + , "src/unix/newlib/powerpc/mod.rs" + , "src/unix/newlib/horizon/mod.rs" + , "src/unix/newlib/espidf/mod.rs" + , "src/unix/hurd/b64.rs" + , "src/unix/hurd/no_align.rs" + , "src/unix/hurd/align.rs" + , "src/unix/hurd/b32.rs" + , "src/unix/hurd/mod.rs" + , "src/unix/linux_like/mod.rs" + , "src/unix/linux_like/linux/no_align.rs" + , "src/unix/linux_like/linux/align.rs" + , "src/unix/linux_like/linux/non_exhaustive.rs" + , "src/unix/linux_like/linux/mod.rs" + , "src/unix/linux_like/linux/arch/mod.rs" + , "src/unix/linux_like/linux/arch/generic/mod.rs" + , "src/unix/linux_like/linux/arch/powerpc/mod.rs" + , "src/unix/linux_like/linux/arch/mips/mod.rs" + , "src/unix/linux_like/linux/arch/sparc/mod.rs" + , "src/unix/linux_like/linux/uclibc/no_align.rs" + , "src/unix/linux_like/linux/uclibc/align.rs" + , "src/unix/linux_like/linux/uclibc/mod.rs" + , "src/unix/linux_like/linux/uclibc/x86_64/l4re.rs" + , "src/unix/linux_like/linux/uclibc/x86_64/other.rs" + , "src/unix/linux_like/linux/uclibc/x86_64/mod.rs" + , "src/unix/linux_like/linux/uclibc/arm/no_align.rs" + , "src/unix/linux_like/linux/uclibc/arm/align.rs" + , "src/unix/linux_like/linux/uclibc/arm/mod.rs" + , "src/unix/linux_like/linux/uclibc/mips/mod.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips32/no_align.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips32/align.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips32/mod.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips64/no_align.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips64/align.rs" + , "src/unix/linux_like/linux/uclibc/mips/mips64/mod.rs" + , "src/unix/linux_like/linux/musl/lfs64.rs" + , "src/unix/linux_like/linux/musl/mod.rs" + , "src/unix/linux_like/linux/musl/b64/s390x.rs" + , "src/unix/linux_like/linux/musl/b64/powerpc64.rs" + , "src/unix/linux_like/linux/musl/b64/mips64.rs" + , "src/unix/linux_like/linux/musl/b64/mod.rs" + , "src/unix/linux_like/linux/musl/b64/x86_64/align.rs" + , "src/unix/linux_like/linux/musl/b64/x86_64/mod.rs" + , "src/unix/linux_like/linux/musl/b64/aarch64/align.rs" + , "src/unix/linux_like/linux/musl/b64/aarch64/int128.rs" + , "src/unix/linux_like/linux/musl/b64/aarch64/mod.rs" + , "src/unix/linux_like/linux/musl/b64/loongarch64/align.rs" + , "src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs" + , "src/unix/linux_like/linux/musl/b64/riscv64/align.rs" + , "src/unix/linux_like/linux/musl/b64/riscv64/mod.rs" + , "src/unix/linux_like/linux/musl/b32/powerpc.rs" + , "src/unix/linux_like/linux/musl/b32/hexagon.rs" + , "src/unix/linux_like/linux/musl/b32/mod.rs" + , "src/unix/linux_like/linux/musl/b32/arm/align.rs" + , "src/unix/linux_like/linux/musl/b32/arm/mod.rs" + , "src/unix/linux_like/linux/musl/b32/riscv32/align.rs" + , "src/unix/linux_like/linux/musl/b32/riscv32/mod.rs" + , "src/unix/linux_like/linux/musl/b32/x86/align.rs" + , "src/unix/linux_like/linux/musl/b32/x86/mod.rs" + , "src/unix/linux_like/linux/musl/b32/mips/align.rs" + , "src/unix/linux_like/linux/musl/b32/mips/mod.rs" + , "src/unix/linux_like/linux/gnu/no_align.rs" + , "src/unix/linux_like/linux/gnu/align.rs" + , "src/unix/linux_like/linux/gnu/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/s390x.rs" + , "src/unix/linux_like/linux/gnu/b64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/x86_64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/x86_64/x32.rs" + , "src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs" + , "src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/ilp32.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/lp64.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/int128.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/fallback.rs" + , "src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/loongarch64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/loongarch64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/riscv64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/powerpc64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/powerpc64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/mips64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/mips64/mod.rs" + , "src/unix/linux_like/linux/gnu/b64/sparc64/align.rs" + , "src/unix/linux_like/linux/gnu/b64/sparc64/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/powerpc.rs" + , "src/unix/linux_like/linux/gnu/b32/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/csky/align.rs" + , "src/unix/linux_like/linux/gnu/b32/csky/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/arm/align.rs" + , "src/unix/linux_like/linux/gnu/b32/arm/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/riscv32/align.rs" + , "src/unix/linux_like/linux/gnu/b32/riscv32/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/x86/align.rs" + , "src/unix/linux_like/linux/gnu/b32/x86/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/mips/align.rs" + , "src/unix/linux_like/linux/gnu/b32/mips/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/m68k/align.rs" + , "src/unix/linux_like/linux/gnu/b32/m68k/mod.rs" + , "src/unix/linux_like/linux/gnu/b32/sparc/align.rs" + , "src/unix/linux_like/linux/gnu/b32/sparc/mod.rs" + , "src/unix/linux_like/android/mod.rs" + , "src/unix/linux_like/android/b64/mod.rs" + , "src/unix/linux_like/android/b64/x86_64/align.rs" + , "src/unix/linux_like/android/b64/x86_64/mod.rs" + , "src/unix/linux_like/android/b64/aarch64/align.rs" + , "src/unix/linux_like/android/b64/aarch64/int128.rs" + , "src/unix/linux_like/android/b64/aarch64/mod.rs" + , "src/unix/linux_like/android/b64/riscv64/align.rs" + , "src/unix/linux_like/android/b64/riscv64/mod.rs" + , "src/unix/linux_like/android/b32/mod.rs" + , "src/unix/linux_like/android/b32/arm.rs" + , "src/unix/linux_like/android/b32/x86/align.rs" + , "src/unix/linux_like/android/b32/x86/mod.rs" + , "src/unix/linux_like/emscripten/no_align.rs" + , "src/unix/linux_like/emscripten/align.rs" + , "src/unix/linux_like/emscripten/lfs64.rs" + , "src/unix/linux_like/emscripten/mod.rs" + , "src/unix/aix/powerpc64.rs" + , "src/unix/aix/mod.rs" + , "src/unix/redox/mod.rs" + , "src/unix/solarish/illumos.rs" + , "src/unix/solarish/compat.rs" + , "src/unix/solarish/x86.rs" + , "src/unix/solarish/solaris.rs" + , "src/unix/solarish/x86_common.rs" + , "src/unix/solarish/x86_64.rs" + , "src/unix/solarish/mod.rs" + , "src/unix/bsd/mod.rs" + , "src/unix/bsd/apple/long_array.rs" + , "src/unix/bsd/apple/mod.rs" + , "src/unix/bsd/apple/b64/align.rs" + , "src/unix/bsd/apple/b64/mod.rs" + , "src/unix/bsd/apple/b64/x86_64/align.rs" + , "src/unix/bsd/apple/b64/x86_64/mod.rs" + , "src/unix/bsd/apple/b64/aarch64/align.rs" + , "src/unix/bsd/apple/b64/aarch64/mod.rs" + , "src/unix/bsd/apple/b32/align.rs" + , "src/unix/bsd/apple/b32/mod.rs" + , "src/unix/bsd/netbsdlike/mod.rs" + , "src/unix/bsd/netbsdlike/netbsd/mips.rs" + , "src/unix/bsd/netbsdlike/netbsd/aarch64.rs" + , "src/unix/bsd/netbsdlike/netbsd/x86.rs" + , "src/unix/bsd/netbsdlike/netbsd/sparc64.rs" + , "src/unix/bsd/netbsdlike/netbsd/riscv64.rs" + , "src/unix/bsd/netbsdlike/netbsd/powerpc.rs" + , "src/unix/bsd/netbsdlike/netbsd/x86_64.rs" + , "src/unix/bsd/netbsdlike/netbsd/mod.rs" + , "src/unix/bsd/netbsdlike/netbsd/arm.rs" + , "src/unix/bsd/netbsdlike/openbsd/aarch64.rs" + , "src/unix/bsd/netbsdlike/openbsd/x86.rs" + , "src/unix/bsd/netbsdlike/openbsd/powerpc64.rs" + , "src/unix/bsd/netbsdlike/openbsd/sparc64.rs" + , "src/unix/bsd/netbsdlike/openbsd/riscv64.rs" + , "src/unix/bsd/netbsdlike/openbsd/powerpc.rs" + , "src/unix/bsd/netbsdlike/openbsd/x86_64.rs" + , "src/unix/bsd/netbsdlike/openbsd/mips64.rs" + , "src/unix/bsd/netbsdlike/openbsd/mod.rs" + , "src/unix/bsd/netbsdlike/openbsd/arm.rs" + , "src/unix/bsd/freebsdlike/mod.rs" + , "src/unix/bsd/freebsdlike/dragonfly/errno.rs" + , "src/unix/bsd/freebsdlike/dragonfly/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/aarch64.rs" + , "src/unix/bsd/freebsdlike/freebsd/x86.rs" + , "src/unix/bsd/freebsdlike/freebsd/powerpc64.rs" + , "src/unix/bsd/freebsdlike/freebsd/riscv64.rs" + , "src/unix/bsd/freebsdlike/freebsd/powerpc.rs" + , "src/unix/bsd/freebsdlike/freebsd/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/arm.rs" + , "src/unix/bsd/freebsdlike/freebsd/x86_64/align.rs" + , "src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd13/b64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd13/x86_64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd15/b64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd15/x86_64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd12/b64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd12/x86_64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd14/b64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd14/x86_64.rs" + , "src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs" + , "src/windows/mod.rs" + , "src/windows/msvc/mod.rs" + , "src/windows/gnu/align.rs" + , "src/windows/gnu/mod.rs" + , "src/hermit/aarch64.rs" + , "src/hermit/x86_64.rs" + , "src/hermit/mod.rs" + , "src/vxworks/aarch64.rs" + , "src/vxworks/x86.rs" + , "src/vxworks/powerpc64.rs" + , "src/vxworks/powerpc.rs" + , "src/vxworks/x86_64.rs" + , "src/vxworks/mod.rs" + , "src/vxworks/arm.rs" + , "src/teeos/mod.rs" + ] + , "edition": ["2015"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [] + , "cargo_features": [] + , "stage": ["libc-0.2.155"] + , "version": ["0", "2", "155"] + , "pkg_name": ["libc"] + , "build_script": ["build_script"] + } +, "build_script": + { "type": ["@", "rules", "cargo", "build_script"] + , "name": ["build_script"] + , "crate_root": ["build.rs"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "edition": ["2015"] + , "stage": ["libc-0.2.155"] + , "deps": [] + , "cargo_features": [] + , "version": ["0", "2", "155"] + , "pkg_name": ["libc"] + } +, "align": {"type": ["@", "rules", "cargo", "feature"], "name": ["align"]} +, "const-extern-fn": + {"type": ["@", "rules", "cargo", "feature"], "name": ["const-extern-fn"]} +, "default": {"type": ["@", "rules", "cargo", "feature"], "name": ["default"]} +, "extra_traits": + {"type": ["@", "rules", "cargo", "feature"], "name": ["extra_traits"]} +, "rustc-dep-of-std": + {"type": ["@", "rules", "cargo", "feature"], "name": ["rustc-dep-of-std"]} +, "rustc-std-workspace-core": + { "type": ["@", "rules", "cargo", "feature"] + , "name": ["rustc-std-workspace-core"] + } +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +, "use_std": {"type": ["@", "rules", "cargo", "feature"], "name": ["use_std"]} +} diff --git a/etc/deps-rust/TARGETS.ppv-lite86-0.2.17 b/etc/deps-rust/TARGETS.ppv-lite86-0.2.17 new file mode 100644 index 0000000..c8c3fd7 --- /dev/null +++ b/etc/deps-rust/TARGETS.ppv-lite86-0.2.17 @@ -0,0 +1,32 @@ +{ "ppv_lite86": + { "type": "export" + , "target": "ppv_lite86-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "ppv_lite86-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["ppv_lite86"] + , "crate_root": ["src/lib.rs"] + , "srcs": + [ "src/soft.rs" + , "src/generic.rs" + , "src/types.rs" + , "src/lib.rs" + , "src/x86_64/sse2.rs" + , "src/x86_64/mod.rs" + ] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [] + , "cargo_features": ["simd", "std"] + , "stage": ["ppv-lite86-0.2.17"] + , "version": ["0", "2", "17"] + , "pkg_name": ["ppv-lite86"] + } +, "default": {"type": ["@", "rules", "cargo", "feature"], "name": ["default"]} +, "no_simd": {"type": ["@", "rules", "cargo", "feature"], "name": ["no_simd"]} +, "simd": {"type": ["@", "rules", "cargo", "feature"], "name": ["simd"]} +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +} diff --git a/etc/deps-rust/TARGETS.rand-0.8.5 b/etc/deps-rust/TARGETS.rand-0.8.5 new file mode 100644 index 0000000..be9e720 --- /dev/null +++ b/etc/deps-rust/TARGETS.rand-0.8.5 @@ -0,0 +1,74 @@ +{ "rand": + { "type": "export" + , "target": "rand-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "rand-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["rand"] + , "crate_root": ["src/lib.rs"] + , "srcs": + [ "src/rng.rs" + , "src/prelude.rs" + , "src/lib.rs" + , "src/distributions/distribution.rs" + , "src/distributions/uniform.rs" + , "src/distributions/weighted.rs" + , "src/distributions/other.rs" + , "src/distributions/weighted_index.rs" + , "src/distributions/bernoulli.rs" + , "src/distributions/integer.rs" + , "src/distributions/float.rs" + , "src/distributions/utils.rs" + , "src/distributions/slice.rs" + , "src/distributions/mod.rs" + , "src/seq/index.rs" + , "src/seq/mod.rs" + , "src/rngs/small.rs" + , "src/rngs/xoshiro128plusplus.rs" + , "src/rngs/thread.rs" + , "src/rngs/std.rs" + , "src/rngs/mock.rs" + , "src/rngs/xoshiro256plusplus.rs" + , "src/rngs/mod.rs" + , "src/rngs/adapter/read.rs" + , "src/rngs/adapter/reseeding.rs" + , "src/rngs/adapter/mod.rs" + ] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": + [ ["@", "libc", "", "libc"] + , ["@", "rand_chacha", "", "rand_chacha"] + , ["@", "rand_core", "", "rand_core"] + ] + , "cargo_features": + ["alloc", "default", "getrandom", "libc", "rand_chacha", "std", "std_rng"] + , "stage": ["rand-0.8.5"] + , "version": ["0", "8", "5"] + , "pkg_name": ["rand"] + } +, "alloc": {"type": ["@", "rules", "cargo", "feature"], "name": ["alloc"]} +, "default": {"type": ["@", "rules", "cargo", "feature"], "name": ["default"]} +, "getrandom": + {"type": ["@", "rules", "cargo", "feature"], "name": ["getrandom"]} +, "libc": {"type": ["@", "rules", "cargo", "feature"], "name": ["libc"]} +, "log": {"type": ["@", "rules", "cargo", "feature"], "name": ["log"]} +, "min_const_gen": + {"type": ["@", "rules", "cargo", "feature"], "name": ["min_const_gen"]} +, "nightly": {"type": ["@", "rules", "cargo", "feature"], "name": ["nightly"]} +, "packed_simd": + {"type": ["@", "rules", "cargo", "feature"], "name": ["packed_simd"]} +, "rand_chacha": + {"type": ["@", "rules", "cargo", "feature"], "name": ["rand_chacha"]} +, "serde": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde"]} +, "serde1": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde1"]} +, "simd_support": + {"type": ["@", "rules", "cargo", "feature"], "name": ["simd_support"]} +, "small_rng": + {"type": ["@", "rules", "cargo", "feature"], "name": ["small_rng"]} +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +, "std_rng": {"type": ["@", "rules", "cargo", "feature"], "name": ["std_rng"]} +} diff --git a/etc/deps-rust/TARGETS.rand_chacha-0.3.1 b/etc/deps-rust/TARGETS.rand_chacha-0.3.1 new file mode 100644 index 0000000..ff88bbd --- /dev/null +++ b/etc/deps-rust/TARGETS.rand_chacha-0.3.1 @@ -0,0 +1,29 @@ +{ "rand_chacha": + { "type": "export" + , "target": "rand_chacha-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "rand_chacha-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["rand_chacha"] + , "crate_root": ["src/lib.rs"] + , "srcs": ["src/chacha.rs", "src/guts.rs", "src/lib.rs"] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": + [ ["@", "ppv-lite86", "", "ppv_lite86"] + , ["@", "rand_core", "", "rand_core"] + ] + , "cargo_features": ["std"] + , "stage": ["rand_chacha-0.3.1"] + , "version": ["0", "3", "1"] + , "pkg_name": ["rand_chacha"] + } +, "default": {"type": ["@", "rules", "cargo", "feature"], "name": ["default"]} +, "serde": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde"]} +, "serde1": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde1"]} +, "simd": {"type": ["@", "rules", "cargo", "feature"], "name": ["simd"]} +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +} diff --git a/etc/deps-rust/TARGETS.rand_core-0.6.4 b/etc/deps-rust/TARGETS.rand_core-0.6.4 new file mode 100644 index 0000000..28896c6 --- /dev/null +++ b/etc/deps-rust/TARGETS.rand_core-0.6.4 @@ -0,0 +1,34 @@ +{ "rand_core": + { "type": "export" + , "target": "rand_core-internal" + , "flexible_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + } +, "rand_core-internal": + { "type": ["@", "rules", "rust", "library"] + , "name": ["rand_core"] + , "crate_root": ["src/lib.rs"] + , "srcs": + [ "src/impls.rs" + , "src/block.rs" + , "src/os.rs" + , "src/le.rs" + , "src/error.rs" + , "src/lib.rs" + ] + , "edition": ["2018"] + , "arguments_config": + ["ARCH", "HOST_ARCH", "TARGET_ARCH", "ENV", "TOOLCHAIN_CONFIG"] + , "deps": [["@", "getrandom", "", "getrandom"]] + , "cargo_features": ["alloc", "getrandom", "std"] + , "stage": ["rand_core-0.6.4"] + , "version": ["0", "6", "4"] + , "pkg_name": ["rand_core"] + } +, "alloc": {"type": ["@", "rules", "cargo", "feature"], "name": ["alloc"]} +, "getrandom": + {"type": ["@", "rules", "cargo", "feature"], "name": ["getrandom"]} +, "serde": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde"]} +, "serde1": {"type": ["@", "rules", "cargo", "feature"], "name": ["serde1"]} +, "std": {"type": ["@", "rules", "cargo", "feature"], "name": ["std"]} +} diff --git a/etc/generate-repos.sh b/etc/generate-repos.sh index 8bd1ca6..d8cd187 100755 --- a/etc/generate-repos.sh +++ b/etc/generate-repos.sh @@ -8,8 +8,15 @@ readonly ROOT=$(readlink -f $(dirname $0)/..) : ${RULES_RUST_REPO:=https://github.com/just-buildsystem/rules-rust} : ${RULES_RUST_BRANCH:=master} +# remove files generated by just-import-cargo +rm -rf etc/deps-rust etc/defaults/rust/TARGETS # common to all cargo imports +rm -f src/rust/cargo/circle/Cargo.lock src/rust/cargo/circle/TARGETS + just-import-git -C ${ROOT}/etc/repos.template.json \ --as rules -b ${RULES_CC_BRANCH} ${RULES_CC_REPO} rules \ | just-import-git -C - \ --as rules-rust -b ${RULES_RUST_BRANCH} ${RULES_RUST_REPO} rules-rust \ + | just-import-cargo --rules rules-rust/nix --repo-root ${ROOT} -rst \ + src/rust/cargo/circle \ + | just-deduplicate-repos \ | hdump > ${ROOT}/etc/repos.json diff --git a/etc/repos.json b/etc/repos.json index 1f68227..3f419a3 100644 --- a/etc/repos.json +++ b/etc/repos.json @@ -5,7 +5,8 @@ } , "test": { "repository": {"type": "file", "path": "test"} - , "bindings": {"rules": "rules/nix-test", "src": ""} + , "bindings": + {"rules": "rules/nix-test", "src": "", "cargo/circle": "circle_sampling"} } , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}} , "rules/nix": @@ -14,6 +15,7 @@ { "repository": "rules-rust" , "target_root": "defaults" , "rule_root": "rules-rust" + , "target_file_name": "nix.TARGETS" } , "rules/nix-test": { "repository": "rules" @@ -36,9 +38,124 @@ { "type": "git" , "repository": "https://github.com/just-buildsystem/rules-rust" , "branch": "master" - , "commit": "bf3e05a614f1de5a9a8a0f8e40f1dd9e1f6609da" + , "commit": "9a4697a2c948a4bcb4a2232a371b6cb3c178e20b" , "subdir": "rules" } } + , "circle_sampling/cfg-if-1.0.0": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/cfg-if/1.0.0/download" + , "content": "c77d9a7af0aea15217dfcdd046013598f696acb0" + , "subdir": "cfg-if-1.0.0" + , "distfile": "cfg-if-1.0.0.tar.gz" + } + , "bindings": {"rules": "circle_sampling/rust-rules"} + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.cfg-if-1.0.0" + } + , "circle_sampling": + { "repository": {"type": "file", "path": "src/rust/cargo/circle"} + , "bindings": + { "rules": "circle_sampling/rust-rules" + , "rand": "circle_sampling/rand-0.8.5" + } + } + , "circle_sampling/getrandom-0.2.15": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/getrandom/0.2.15/download" + , "content": "8c167a8cdc3f6f149dd3f37ba9c6932a2592052a" + , "subdir": "getrandom-0.2.15" + , "distfile": "getrandom-0.2.15.tar.gz" + } + , "bindings": + { "rules": "circle_sampling/rust-rules" + , "cfg-if": "circle_sampling/cfg-if-1.0.0" + , "libc": "circle_sampling/libc-0.2.155" + } + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.getrandom-0.2.15" + } + , "circle_sampling/libc-0.2.155": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/libc/0.2.155/download" + , "content": "67353d815cff7dd0c37e4426c338bf7f2534a5c1" + , "subdir": "libc-0.2.155" + , "distfile": "libc-0.2.155.tar.gz" + } + , "bindings": {"rules": "circle_sampling/rust-rules"} + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.libc-0.2.155" + } + , "circle_sampling/ppv-lite86-0.2.17": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/ppv-lite86/0.2.17/download" + , "content": "b142c0fb86f0c3c585c1579a7d671b78441cad27" + , "subdir": "ppv-lite86-0.2.17" + , "distfile": "ppv-lite86-0.2.17.tar.gz" + } + , "bindings": {"rules": "circle_sampling/rust-rules"} + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.ppv-lite86-0.2.17" + } + , "circle_sampling/rand-0.8.5": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/rand/0.8.5/download" + , "content": "768d8f0c5c7abe7eb847ffc1a0ff6e3e5ccc49d3" + , "subdir": "rand-0.8.5" + , "distfile": "rand-0.8.5.tar.gz" + } + , "bindings": + { "rules": "circle_sampling/rust-rules" + , "libc": "circle_sampling/libc-0.2.155" + , "rand_chacha": "circle_sampling/rand_chacha-0.3.1" + , "rand_core": "circle_sampling/rand_core-0.6.4" + } + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.rand-0.8.5" + } + , "circle_sampling/rand_chacha-0.3.1": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/rand_chacha/0.3.1/download" + , "content": "67d1b4ac6de64f68ced704ee6133b6e97976eadc" + , "subdir": "rand_chacha-0.3.1" + , "distfile": "rand_chacha-0.3.1.tar.gz" + } + , "bindings": + { "rules": "circle_sampling/rust-rules" + , "ppv-lite86": "circle_sampling/ppv-lite86-0.2.17" + , "rand_core": "circle_sampling/rand_core-0.6.4" + } + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.rand_chacha-0.3.1" + } + , "circle_sampling/rand_core-0.6.4": + { "repository": + { "type": "archive" + , "fetch": "https://crates.io/api/v1/crates/rand_core/0.6.4/download" + , "content": "7fb776b46fd89e927d5ea0f5df0c220ce650c7dc" + , "subdir": "rand_core-0.6.4" + , "distfile": "rand_core-0.6.4.tar.gz" + } + , "bindings": + { "rules": "circle_sampling/rust-rules" + , "getrandom": "circle_sampling/getrandom-0.2.15" + } + , "target_root": "circle_sampling/external-deps" + , "target_file_name": "TARGETS.rand_core-0.6.4" + } + , "circle_sampling/external-deps": + {"repository": {"type": "file", "path": "etc/deps-rust"}} + , "circle_sampling/rust-rules": + { "repository": "rules-rust" + , "target_root": "defaults" + , "rule_root": "rules-rust" + , "bindings": {"orig-rules": "rules-rust/nix"} + } } } diff --git a/etc/repos.template.json b/etc/repos.template.json index 929e149..1b898be 100644 --- a/etc/repos.template.json +++ b/etc/repos.template.json @@ -5,7 +5,8 @@ } , "test": { "repository": {"type": "file", "path": "test"} - , "bindings": {"rules": "rules/nix-test", "src": ""} + , "bindings": + {"rules": "rules/nix-test", "src": "", "cargo/circle": "circle_sampling"} } , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}} , "rules/nix": @@ -14,6 +15,7 @@ { "repository": "rules-rust" , "target_root": "defaults" , "rule_root": "rules-rust" + , "target_file_name": "nix.TARGETS" } , "rules/nix-test": { "repository": "rules" diff --git a/nix-dependencies/dependencies.nix b/nix-dependencies/dependencies.nix index a328ddd..10a1b3e 100644 --- a/nix-dependencies/dependencies.nix +++ b/nix-dependencies/dependencies.nix @@ -7,10 +7,12 @@ , clang , fmt , rustc +, busybox # for tests , gnugrep , unixtools +, python3 }: stdenv.mkDerivation rec { @@ -42,10 +44,11 @@ stdenv.mkDerivation rec { GRPC_PLUGIN=${grpc}/bin/grpc_cpp_plugin \ ) \ shell=$(jo PATH=$(jo -a ${coreutils}/bin)) \ - test=$(jo PATH=$(jo -a ${gnugrep}/bin ${unixtools.xxd}/bin)) \ + test=$(jo PATH=$(jo -a ${gnugrep}/bin ${unixtools.xxd}/bin ${python3}/bin)) \ PKGCONFIG=$(jo pkg-config=${pkg-config}/bin/pkg-config \ PKG_CONFIG_PATH=$(jo -a $PKG_CONFIG_PATH)) \ - RUST=$(jo PATH=$(jo -a ${rustc}/bin ${clang}/bin ${coreutils}/bin /bin)) \ + RUST=$(jo PATH=$(jo -a ${rustc}/bin ${clang}/bin ${coreutils}/bin \ + ${busybox}/bin)) \ ) > config.json cat config.json jo "just files"=$(jo config=$(jo -a $(jo root=system path=$out/share/config.json))) > rc.json diff --git a/nix-import-tools/import-tools.nix b/nix-import-tools/import-tools.nix index cfb7a91..b12023b 100644 --- a/nix-import-tools/import-tools.nix +++ b/nix-import-tools/import-tools.nix @@ -26,7 +26,9 @@ stdenv.mkDerivation rec { unpackPhase = '' cp $srcjust/bin/just-import-git.py . + cp $srcjust/bin/just-deduplicate-repos.py . cp $srcrustrules/bin/hdump.py . + cp $srcrustrules/bin/just-import-cargo.py . ''; dontBuild = true; @@ -34,8 +36,11 @@ stdenv.mkDerivation rec { installPhase = '' mkdir -p $out/bin cp just-import-git.py $out/bin/just-import-git + cp just-deduplicate-repos.py $out/bin/just-deduplicate-repos cp hdump.py $out/bin/hdump - chmod 555 $out/bin/just-import-git $out/bin/hdump + cp just-import-cargo.py $out/bin/just-import-cargo + chmod 555 $out/bin/just-import-git $out/bin/just-deduplicate-repos + chmod 555 $out/bin/hdump $out/bin/just-import-cargo ''; } @@ -16,6 +16,7 @@ in pkgs.mkShell rec { buildInputs = with pkgs; [ niv update-deps + cargo ]; shellHook = '' 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}") +} diff --git a/test/rust/TARGETS b/test/rust/TARGETS index 713ff64..d62b2d3 100644 --- a/test/rust/TARGETS +++ b/test/rust/TARGETS @@ -3,6 +3,7 @@ , "tainted": ["test"] , "dirs": [ [["./", "hello", ""], "hello"] + , [["./", "cargo", ""], "cargo"] ] } } diff --git a/test/rust/cargo/TARGETS b/test/rust/cargo/TARGETS new file mode 100644 index 0000000..1552a32 --- /dev/null +++ b/test/rust/cargo/TARGETS @@ -0,0 +1,8 @@ +{ "": + { "type": "install" + , "tainted": ["test"] + , "dirs": + [ [["./", "circle", ""], "circle"] + ] + } +} diff --git a/test/rust/cargo/circle/TARGETS b/test/rust/cargo/circle/TARGETS new file mode 100644 index 0000000..565bb37 --- /dev/null +++ b/test/rust/cargo/circle/TARGETS @@ -0,0 +1,13 @@ +{ "": {"type": "install", "tainted": ["test"], "deps": ["test-sampling"]} +, "test-sampling": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["sampling"] + , "test": ["test_circle_sampling.sh"] + , "deps": ["sample", "verify.py"] + , "keep": ["sampled"] + } +, "sample": + { "type": "install" + , "files": {"bin/sample": ["@", "cargo/circle", "", "circle_sampling"]} + } +} diff --git a/test/rust/cargo/circle/test_circle_sampling.sh b/test/rust/cargo/circle/test_circle_sampling.sh new file mode 100644 index 0000000..c22109a --- /dev/null +++ b/test/rust/cargo/circle/test_circle_sampling.sh @@ -0,0 +1,8 @@ +set -e + +for _ in `seq 1 100` +do + ./bin/sample >> sampled +done + +python3 verify.py sampled diff --git a/test/rust/cargo/circle/verify.py b/test/rust/cargo/circle/verify.py new file mode 100644 index 0000000..09dccee --- /dev/null +++ b/test/rust/cargo/circle/verify.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import math +import sys + +with open(sys.argv[1]) as f: + samples = f.read() + +for line in samples.splitlines(): + xs, ys = line.split() + x = int(xs) + y = int(ys) + radius = math.sqrt(x*x + y*y) + print ("(%+3d,%+3d) -> %4.1f" % (x,y,radius)) + if radius > 100.0: + sys.exit(1) |