diff --git a/.gitignore b/.gitignore index 82f4286297..89ef98427f 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ storybook-static envs/qwerty.env .parcel-cache **/.DS_Store +cpu-cycles/libcpucycles/build \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 662c55f585..e168a3d9b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,6 +886,14 @@ dependencies = [ "uint", ] +[[package]] +name = "cpu-cycles" +version = "0.1.0" +dependencies = [ + "cfg-if", + "libc", +] + [[package]] name = "cpufeatures" version = "0.2.5" @@ -3495,6 +3503,7 @@ dependencies = [ "bs58", "clap 4.1.11", "colored", + "cpu-cycles", "cupid", "dirs", "futures", diff --git a/cpu-cycles/Cargo.toml b/cpu-cycles/Cargo.toml new file mode 100644 index 0000000000..59d2ed52b6 --- /dev/null +++ b/cpu-cycles/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "cpu-cycles" +version = "0.1.0" +edition = "2021" +build = "build.rs" +links = "cpucycles" + +[dependencies] +libc = "0.2.140" + +[build-dependencies] +cfg-if = "1" \ No newline at end of file diff --git a/cpu-cycles/build.rs b/cpu-cycles/build.rs new file mode 100644 index 0000000000..d86a4f6df3 --- /dev/null +++ b/cpu-cycles/build.rs @@ -0,0 +1,65 @@ +use std::{env, path::PathBuf, process::Command}; + +fn main() { + let out_dir = env::var("OUT_DIR").unwrap(); + let out_path = PathBuf::from(&out_dir); + let source_path = PathBuf::from("libcpucycles") + .canonicalize() + .expect("cannot canonicalize path"); + + cfg_if::cfg_if! { + if #[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "mips", target_arch = "powerpc", target_arch = "powerpc64", target_arch = "arm")))] { + panic!("Unsupported architecture - {}!", env::var("CARGO_CFG_TARGET_ARCH").unwrap(), ) + } + }; + + let mut compile_o_command = Command::new("./configure"); + let compile_o_command = compile_o_command + .current_dir(&source_path) + .arg(format!("--prefix={out_dir}")); + + match compile_o_command.output() { + Ok(output) => { + if !output.status.success() { + panic!("{:?}", unsafe { + std::str::from_utf8_unchecked(&output.stderr) + }) + } + } + Err(e) => panic!("{e}"), + } + + let mut compile_o_command = Command::new("make"); + let compile_o_command = compile_o_command.current_dir(&source_path).arg("install"); + + match compile_o_command.output() { + Ok(output) => { + if !output.status.success() { + panic!("{:?}", unsafe { + std::str::from_utf8_unchecked(&output.stderr) + }) + } + } + Err(e) => panic!("{e}"), + } + + println!( + "cargo:rustc-link-search=native={}", + out_path.join("lib").to_str().unwrap() + ); + println!("cargo:rustc-link-lib=static=cpucycles"); + + let mut compile_o_command = Command::new("make"); + let compile_o_command = compile_o_command.current_dir(source_path).arg("clean"); + + match compile_o_command.output() { + Ok(output) => { + if !output.status.success() { + panic!("{:?}", unsafe { + std::str::from_utf8_unchecked(&output.stderr) + }) + } + } + Err(e) => panic!("{e}"), + } +} diff --git a/cpu-cycles/libcpucycles/Makefile b/cpu-cycles/libcpucycles/Makefile new file mode 100644 index 0000000000..8968a9bf80 --- /dev/null +++ b/cpu-cycles/libcpucycles/Makefile @@ -0,0 +1,8 @@ +default: + cd build && $(MAKE) + +install: + cd build && $(MAKE) install + +clean: + cd build && $(MAKE) clean diff --git a/cpu-cycles/libcpucycles/autogen/html b/cpu-cycles/libcpucycles/autogen/html new file mode 100755 index 0000000000..84a0ff2dab --- /dev/null +++ b/cpu-cycles/libcpucycles/autogen/html @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +import os +import datetime +import markdown + +def load(fn): + with open(fn) as f: + return f.read() + +style = load('autogen/html-style') +sitetitle = load('autogen/html-title') + +files = [] + +with open('autogen/html-files') as f: + for line in f: + line = line.strip() + line = line.split(':') + if len(line) != 3: continue + files += [line] + +for md,html,pagetitle in files: + fnmd = 'doc/%s.md' % md + fnhtml = 'doc/html/%s.html' % html + output = '' + + x = load(fnmd) + x = markdown.markdown(x,extensions=['markdown.extensions.extra','markdown.extensions.tables']) + mtime = datetime.datetime.utcfromtimestamp(os.path.getmtime(fnmd)).strftime('%Y.%m.%d') + + output += '\n\n' + output += style + output += '\n' + output += pagetitle + output += '\n' + output += '\n' + output += '\n' + + output += '
\n' + output += sitetitle + output += '
\n' + + output += '