diff --git a/Cargo.lock b/Cargo.lock index e262a0b76a..8bacd12621 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -282,6 +282,28 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "383d29d513d8764dcdc42ea295d979eb99c3c9f00607b3692cf68a431f7dca72" +[[package]] +name = "bindgen" +version = "0.64.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + [[package]] name = "bip32" version = "0.3.0" @@ -464,6 +486,15 @@ dependencies = [ "jobserver", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -567,6 +598,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clang-sys" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "3.2.23" @@ -879,6 +921,16 @@ dependencies = [ "uint", ] +[[package]] +name = "cpu-cycles" +version = "0.1.0" +dependencies = [ + "bindgen", + "cfg-if", + "libc", + "thiserror", +] + [[package]] name = "cpufeatures" version = "0.2.5" @@ -2656,6 +2708,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "ledger" version = "0.1.0" @@ -2706,9 +2764,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libgit2-sys" @@ -2722,6 +2780,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libm" version = "0.2.6" @@ -3498,6 +3566,7 @@ dependencies = [ "bs58", "clap 4.1.4", "colored", + "cpu-cycles", "cupid", "dirs", "futures", @@ -4226,6 +4295,12 @@ dependencies = [ "syn", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "peg" version = "0.7.0" @@ -5094,6 +5169,12 @@ dependencies = [ "syn", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.2.3" @@ -5503,6 +5584,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + [[package]] name = "signal-hook" version = "0.3.14" @@ -6996,6 +7083,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "which" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/common/cpu-cycles/cpucycles/cpucycles.o b/common/cpu-cycles/cpucycles/cpucycles.o deleted file mode 100644 index 797fa448d8..0000000000 Binary files a/common/cpu-cycles/cpucycles/cpucycles.o and /dev/null differ diff --git a/common/cpu-cycles/Cargo.toml b/cpu-cycles/Cargo.toml similarity index 87% rename from common/cpu-cycles/Cargo.toml rename to cpu-cycles/Cargo.toml index 7f24f60730..4f86f3ef38 100644 --- a/common/cpu-cycles/Cargo.toml +++ b/cpu-cycles/Cargo.toml @@ -10,6 +10,4 @@ thiserror = "1" [build-dependencies] bindgen = "0.64.0" -cfg-if = "1" - -[workspace] +cfg-if = "1" \ No newline at end of file diff --git a/common/cpu-cycles/build.rs b/cpu-cycles/build.rs similarity index 84% rename from common/cpu-cycles/build.rs rename to cpu-cycles/build.rs index 28909f3300..e5665eff04 100644 --- a/common/cpu-cycles/build.rs +++ b/cpu-cycles/build.rs @@ -1,7 +1,7 @@ extern crate bindgen; use cfg_if; -use std::path::PathBuf; +use std::{env, path::PathBuf, process::Command}; use bindgen::CargoCallbacks; @@ -50,23 +50,30 @@ fn main() { } else if #[cfg(all(target_arch = "arm", target_pointer_width = "64"))] { src_path = "arm64-pmc.c".to_string() } else { - panic!("Unsupported architecture!") + panic!("Unsupported architecture ({:?})!", env::var("CARGO_CFG_TARGET_ARCH"), ) } }; // Run `clang` to compile the `hello.c` file into a `hello.o` object file. // Unwrap if it is not possible to spawn the process. - if !std::process::Command::new("clang") + let mut compile_o_command = Command::new("clang"); + let compile_o_command = compile_o_command .arg("-c") .arg("-o") .arg(&obj_path) - .arg(libdir_path.join(&src_path)) - .output() - .expect("could not spawn `clang`") - .status - .success() - { - panic!("could not compile object file") + .arg(libdir_path.join(&src_path)); + + println!("Running: {:?}", compile_o_command); + + match compile_o_command.output() { + Ok(output) => { + if !output.status.success() { + panic!("{:?}", unsafe { + std::str::from_utf8_unchecked(&output.stderr) + }) + } + } + Err(e) => panic!("{e}"), } // Run `ar` to generate the `libhello.a` file from the `hello.o` file. diff --git a/common/cpu-cycles/cpucycles/amd64-pmc.c b/cpu-cycles/cpucycles/amd64-pmc.c similarity index 100% rename from common/cpu-cycles/cpucycles/amd64-pmc.c rename to cpu-cycles/cpucycles/amd64-pmc.c diff --git a/common/cpu-cycles/cpucycles/amd64-tsc.c b/cpu-cycles/cpucycles/amd64-tsc.c similarity index 100% rename from common/cpu-cycles/cpucycles/amd64-tsc.c rename to cpu-cycles/cpucycles/amd64-tsc.c diff --git a/common/cpu-cycles/cpucycles/amd64-tscasm.c b/cpu-cycles/cpucycles/amd64-tscasm.c similarity index 100% rename from common/cpu-cycles/cpucycles/amd64-tscasm.c rename to cpu-cycles/cpucycles/amd64-tscasm.c diff --git a/common/cpu-cycles/cpucycles/arm32-cortex.c b/cpu-cycles/cpucycles/arm32-cortex.c similarity index 100% rename from common/cpu-cycles/cpucycles/arm32-cortex.c rename to cpu-cycles/cpucycles/arm32-cortex.c diff --git a/common/cpu-cycles/cpucycles/arm64-pmc.c b/cpu-cycles/cpucycles/arm64-pmc.c similarity index 100% rename from common/cpu-cycles/cpucycles/arm64-pmc.c rename to cpu-cycles/cpucycles/arm64-pmc.c diff --git a/common/cpu-cycles/cpucycles/arm64-vct.c b/cpu-cycles/cpucycles/arm64-vct.c similarity index 100% rename from common/cpu-cycles/cpucycles/arm64-vct.c rename to cpu-cycles/cpucycles/arm64-vct.c diff --git a/common/cpu-cycles/cpucycles/cpucycles.h b/cpu-cycles/cpucycles/cpucycles.h similarity index 100% rename from common/cpu-cycles/cpucycles/cpucycles.h rename to cpu-cycles/cpucycles/cpucycles.h diff --git a/common/cpu-cycles/cpucycles/cpucycles_internal.h b/cpu-cycles/cpucycles/cpucycles_internal.h similarity index 100% rename from common/cpu-cycles/cpucycles/cpucycles_internal.h rename to cpu-cycles/cpucycles/cpucycles_internal.h diff --git a/common/cpu-cycles/cpucycles/default-gettimeofday.c b/cpu-cycles/cpucycles/default-gettimeofday.c similarity index 100% rename from common/cpu-cycles/cpucycles/default-gettimeofday.c rename to cpu-cycles/cpucycles/default-gettimeofday.c diff --git a/common/cpu-cycles/cpucycles/default-mach.c b/cpu-cycles/cpucycles/default-mach.c similarity index 100% rename from common/cpu-cycles/cpucycles/default-mach.c rename to cpu-cycles/cpucycles/default-mach.c diff --git a/common/cpu-cycles/cpucycles/default-monotonic.c b/cpu-cycles/cpucycles/default-monotonic.c similarity index 100% rename from common/cpu-cycles/cpucycles/default-monotonic.c rename to cpu-cycles/cpucycles/default-monotonic.c diff --git a/common/cpu-cycles/cpucycles/default-perfevent.c b/cpu-cycles/cpucycles/default-perfevent.c similarity index 100% rename from common/cpu-cycles/cpucycles/default-perfevent.c rename to cpu-cycles/cpucycles/default-perfevent.c diff --git a/common/cpu-cycles/cpucycles/default-zero.c b/cpu-cycles/cpucycles/default-zero.c similarity index 100% rename from common/cpu-cycles/cpucycles/default-zero.c rename to cpu-cycles/cpucycles/default-zero.c diff --git a/common/cpu-cycles/cpucycles/libcpucycles.a b/cpu-cycles/cpucycles/libcpucycles.a similarity index 100% rename from common/cpu-cycles/cpucycles/libcpucycles.a rename to cpu-cycles/cpucycles/libcpucycles.a diff --git a/common/cpu-cycles/cpucycles/mips64-cc.c b/cpu-cycles/cpucycles/mips64-cc.c similarity index 100% rename from common/cpu-cycles/cpucycles/mips64-cc.c rename to cpu-cycles/cpucycles/mips64-cc.c diff --git a/common/cpu-cycles/cpucycles/options b/cpu-cycles/cpucycles/options similarity index 100% rename from common/cpu-cycles/cpucycles/options rename to cpu-cycles/cpucycles/options diff --git a/common/cpu-cycles/cpucycles/ppc32-mftb.c b/cpu-cycles/cpucycles/ppc32-mftb.c similarity index 100% rename from common/cpu-cycles/cpucycles/ppc32-mftb.c rename to cpu-cycles/cpucycles/ppc32-mftb.c diff --git a/common/cpu-cycles/cpucycles/ppc64-mftb.c b/cpu-cycles/cpucycles/ppc64-mftb.c similarity index 100% rename from common/cpu-cycles/cpucycles/ppc64-mftb.c rename to cpu-cycles/cpucycles/ppc64-mftb.c diff --git a/common/cpu-cycles/cpucycles/riscv32-rdcycle.c b/cpu-cycles/cpucycles/riscv32-rdcycle.c similarity index 100% rename from common/cpu-cycles/cpucycles/riscv32-rdcycle.c rename to cpu-cycles/cpucycles/riscv32-rdcycle.c diff --git a/common/cpu-cycles/cpucycles/riscv64-rdcycle.c b/cpu-cycles/cpucycles/riscv64-rdcycle.c similarity index 100% rename from common/cpu-cycles/cpucycles/riscv64-rdcycle.c rename to cpu-cycles/cpucycles/riscv64-rdcycle.c diff --git a/common/cpu-cycles/cpucycles/s390x-stckf.c b/cpu-cycles/cpucycles/s390x-stckf.c similarity index 100% rename from common/cpu-cycles/cpucycles/s390x-stckf.c rename to cpu-cycles/cpucycles/s390x-stckf.c diff --git a/common/cpu-cycles/cpucycles/sparc64-rdtick.c b/cpu-cycles/cpucycles/sparc64-rdtick.c similarity index 100% rename from common/cpu-cycles/cpucycles/sparc64-rdtick.c rename to cpu-cycles/cpucycles/sparc64-rdtick.c diff --git a/common/cpu-cycles/cpucycles/wrapper.c b/cpu-cycles/cpucycles/wrapper.c similarity index 100% rename from common/cpu-cycles/cpucycles/wrapper.c rename to cpu-cycles/cpucycles/wrapper.c diff --git a/common/cpu-cycles/cpucycles/x86-tsc.c b/cpu-cycles/cpucycles/x86-tsc.c similarity index 100% rename from common/cpu-cycles/cpucycles/x86-tsc.c rename to cpu-cycles/cpucycles/x86-tsc.c diff --git a/common/cpu-cycles/cpucycles/x86-tscasm.c b/cpu-cycles/cpucycles/x86-tscasm.c similarity index 100% rename from common/cpu-cycles/cpucycles/x86-tscasm.c rename to cpu-cycles/cpucycles/x86-tscasm.c diff --git a/common/cpu-cycles/src/bindings.rs b/cpu-cycles/src/bindings.rs similarity index 100% rename from common/cpu-cycles/src/bindings.rs rename to cpu-cycles/src/bindings.rs diff --git a/common/cpu-cycles/src/lib.rs b/cpu-cycles/src/lib.rs similarity index 100% rename from common/cpu-cycles/src/lib.rs rename to cpu-cycles/src/lib.rs diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index d4bf22746c..c0a3d35486 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -29,32 +29,38 @@ log = { workspace = true } pretty_env_logger = "0.4.0" rand = "0.7.3" rocket = { version = "0.5.0-rc.2", features = ["json"] } -serde = { version="1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sysinfo = "0.27.7" -tokio = { version="1.21.2", features = ["rt-multi-thread", "net", "signal"] } -tokio-util = { version="0.7.3", features = ["codec"] } +tokio = { version = "1.21.2", features = ["rt-multi-thread", "net", "signal"] } +tokio-util = { version = "0.7.3", features = ["codec"] } toml = "0.5.8" url = { version = "2.2", features = ["serde"] } atty = "0.2" ## internal -nym-config = { path="../common/config" } -nym-crypto = { path="../common/crypto" } +nym-config = { path = "../common/config" } +nym-crypto = { path = "../common/crypto" } nym-contracts-common = { path = "../common/cosmwasm-smart-contracts/contracts-common" } -mixnet-client = { path="../common/client-libs/mixnet-client" } -mixnode-common = { path="../common/mixnode-common" } -nym-nonexhaustive-delayqueue = { path="../common/nonexhaustive-delayqueue" } -nym-sphinx = { path="../common/nymsphinx" } +mixnet-client = { path = "../common/client-libs/mixnet-client" } +mixnode-common = { path = "../common/mixnode-common" } +nym-nonexhaustive-delayqueue = { path = "../common/nonexhaustive-delayqueue" } +nym-sphinx = { path = "../common/nymsphinx" } nym-pemstore = { path = "../common/pemstore", version = "0.2.0" } nym-task = { path = "../common/task" } nym-types = { path = "../common/types" } -nym-topology = { path="../common/topology" } -validator-client = { path="../common/client-libs/validator-client" } -nym-bin-common = { path="../common/bin-common" } +nym-topology = { path = "../common/topology" } +validator-client = { path = "../common/client-libs/validator-client" } +nym-bin-common = { path = "../common/bin-common" } +cpu-cycles = { path = "../cpu-cycles", optional = true } [dev-dependencies] -tokio = { version="1.21.2", features = ["rt-multi-thread", "net", "signal", "test-util"] } +tokio = { version = "1.21.2", features = [ + "rt-multi-thread", + "net", + "signal", + "test-util", +] } nym-sphinx-types = { path = "../common/nymsphinx/types" } nym-sphinx-params = { path = "../common/nymsphinx/params" } diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index 92b28cb6b8..609e63a0ad 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -60,6 +60,11 @@ impl Cli { } } +#[cfg(feature = "cpu-cycles")] +pub fn cpu_cycles() { + info!("{}", cpu_cycles::cpucycles()) +} + #[tokio::main] async fn main() { setup_logging();