diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-22 15:55:25 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-22 15:55:25 +0100 |
| commit | b4a779f040f18257fde1c357626461ab187490db (patch) | |
| tree | ff4006cff95e0048a6c2816678a640ca0891fe60 | |
| parent | e3e54cfee6ebc17281bbbf906ff9035f594313cd (diff) | |
| download | tools.nes-b4a779f040f18257fde1c357626461ab187490db.tar.gz tools.nes-b4a779f040f18257fde1c357626461ab187490db.zip | |
Remove dependency to the rand crate
This dependency was easily avoidable and it brought with it a lot of
inner dependencies of its own, most notably 'zerocopy-derive', which
forbid us to compile the affected programs purely statically.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
| -rw-r--r-- | Cargo.lock | 97 | ||||
| -rw-r--r-- | crates/xa65/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/xa65/src/main.rs | 13 | ||||
| -rw-r--r-- | lib/xixanta/Cargo.toml | 1 | ||||
| -rw-r--r-- | lib/xixanta/fuzz/Cargo.lock | 90 | ||||
| -rw-r--r-- | lib/xixanta/src/parser.rs | 13 |
6 files changed, 20 insertions, 195 deletions
@@ -52,18 +52,6 @@ dependencies = [ ] [[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] name = "clap" version = "4.5.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -116,17 +104,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[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 = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -165,12 +142,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] -name = "libc" -version = "0.2.169" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" - -[[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -199,15 +170,6 @@ dependencies = [ ] [[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] name = "proc-macro2" version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -226,36 +188,6 @@ dependencies = [ ] [[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 = "readrom" version = "1.0.0" dependencies = [ @@ -357,12 +289,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -449,7 +375,6 @@ name = "xa65" version = "0.1.0" dependencies = [ "clap", - "rand", ] [[package]] @@ -457,27 +382,5 @@ name = "xixanta" version = "0.1.0" dependencies = [ "lazy_static", - "rand", "toml", ] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/crates/xa65/Cargo.toml b/crates/xa65/Cargo.toml index a6696bd..1ecceb0 100644 --- a/crates/xa65/Cargo.toml +++ b/crates/xa65/Cargo.toml @@ -6,4 +6,3 @@ authors = ["Miquel Sabaté Solà <mikisabate@gmail.com>"] [dependencies] clap = { version = "^4", features = ["derive"] } -rand = "0.8.5" diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs index 5d46ec1..8a31e7b 100644 --- a/crates/xa65/src/main.rs +++ b/crates/xa65/src/main.rs @@ -1,5 +1,4 @@ use clap::Parser as ClapParser; -use rand::distributions::{Alphanumeric, DistString}; use std::path::PathBuf; use std::process::Command; @@ -63,6 +62,15 @@ fn get_binaries() -> Result<(PathBuf, PathBuf), String> { Ok((nasm, cl65)) } +// Returns the path to the temporary directory that can be used for the run. +fn temporary_dir() -> PathBuf { + let tmp = &std::env::temp_dir(); + let paths = std::fs::read_dir(tmp).unwrap(); + let name = format!("xa65-{}", paths.count()); + + tmp.join(name) +} + fn main() { // Make sure that the binaries are there. let (nasm, cl65) = match get_binaries() { @@ -87,8 +95,7 @@ fn main() { // Generate a temporary directory in which both binary files will be placed // as an intermediate step. - let random_string = &Alphanumeric.sample_string(&mut rand::thread_rng(), 16); - let dir = std::env::temp_dir().join(random_string); + let dir = temporary_dir(); if let Err(e) = std::fs::create_dir(&dir) { die(e.to_string()); return; diff --git a/lib/xixanta/Cargo.toml b/lib/xixanta/Cargo.toml index 6d2c66a..ada2ded 100644 --- a/lib/xixanta/Cargo.toml +++ b/lib/xixanta/Cargo.toml @@ -11,4 +11,3 @@ rust-version.workspace = true [dependencies] lazy_static = "1.5.0" toml = { version = "0.8", features = ["preserve_order"] } -rand = "0.8.5" diff --git a/lib/xixanta/fuzz/Cargo.lock b/lib/xixanta/fuzz/Cargo.lock index 5122055..eb897dd 100644 --- a/lib/xixanta/fuzz/Cargo.lock +++ b/lib/xixanta/fuzz/Cargo.lock @@ -9,12 +9,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" [[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] name = "cc" version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -26,29 +20,12 @@ dependencies = [ ] [[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[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 = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -109,15 +86,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - -[[package]] name = "proc-macro2" version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -136,36 +104,6 @@ dependencies = [ ] [[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 = "serde" version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -253,12 +191,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] name = "winnow" version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -272,7 +204,6 @@ name = "xixanta" version = "0.1.0" dependencies = [ "lazy_static", - "rand", "toml", ] @@ -283,24 +214,3 @@ dependencies = [ "libfuzzer-sys", "xixanta", ] - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index 0a4d2b8..d508003 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -1,7 +1,6 @@ use crate::node::{ControlType, NodeBodyType, NodeType, OperationType, PNode, PString}; use crate::opcodes::{CONTROL_FUNCTIONS, INSTRUCTIONS}; use crate::{Error, SourceInfo}; -use rand::distributions::{Alphanumeric, DistString}; use std::cmp::Ordering; use std::io::{self, BufRead, Read}; use std::path; @@ -61,6 +60,12 @@ pub struct Parser { /// look ahead to know where the literal ends before dealing with further /// operators. look_ahead_index: usize, + + /// Number that keeps track of random identifiers being generated so far. + /// This is because certain anonymous identifiers are not to be exposed to + /// the human eye, and we just care about them being unique. Hence this + /// counter. + generated_identifiers: usize, } impl Parser { @@ -1338,8 +1343,10 @@ impl Parser { } // Generate a unique identifier with the given prefix. - fn unique_identifier(&self, prefix: String) -> String { - prefix + &String::from("-") + &Alphanumeric.sample_string(&mut rand::thread_rng(), 16) + fn unique_identifier(&mut self, prefix: String) -> String { + let res = prefix + &String::from("-") + &self.generated_identifiers.to_string(); + self.generated_identifiers += 1; + res } // Returns a NodeType::Control node with whatever could be parsed |
