added exit_no_std and better builds

This commit is contained in:
Emma Tebibyte 2022-12-19 20:55:48 -05:00
parent a74b0fede2
commit 7128f8d673
5 changed files with 67 additions and 15 deletions

10
.cargo/config.toml Normal file
View File

@ -0,0 +1,10 @@
[unstable]
build-std = [ "std", "panic_abort" ]
build-std-features = [ "panic_immediate_abort" ]
[profile.release]
strip = true # strip symbols from the binary
opt-level = "z" # optimize for size
lto = true # link time optimization
codegen-units = 1 # decrease parallelization
panic = "abort"

46
Cargo.lock generated
View File

@ -2,6 +2,29 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "exit-no-std"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a608ccc67fac78c1916aa88ad75d6f6a3e353521844abce906c22a45d161d99"
dependencies = [
"libc",
"pc-ints",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "pc-ints"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "422b0cc3a966f6e0987d2f948c234585bd917a1f16df1470e60c56ad6de2c085"
[[package]]
name = "serde"
version = "1.0.148"
@ -12,6 +35,7 @@ checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
name = "tomcat"
version = "0.0.1"
dependencies = [
"exit-no-std",
"toml",
]
@ -23,3 +47,25 @@ checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -6,11 +6,5 @@ license = "AGPL-3.0-or-later"
authors = [ "Emma Tebibyte <emma@tebibyte.media>" ]
[dependencies]
exit-no-std = "0.1.3"
toml = "0.5.9"
[profile.release]
strip = true # strip symbols from the binary
opt-level = "z" # optimize for size
lto = true # link time optimization
codegen-units = 1 # decrease parallelization
panic = "abort"

2
rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@ -19,7 +19,7 @@ use std::env;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::process;
use exit_no_std::exit;
use std::str::FromStr;
use toml::Value;
@ -29,7 +29,7 @@ fn main() {
let argv0 = arguments.remove(0);
if arguments[1].is_empty() {
eprintln!("Usage: {} [table...].[value[index]] [file...]", argv0);
process::exit(64); // sysexits(3) EX_USAGE
exit(64); // sysexits(3) EX_USAGE
}
let input = &arguments[1];
let mut content = String::new();
@ -53,7 +53,7 @@ fn main() {
Ok(i) => index = i,
Err(_) => {
eprintln!("{}: {}: Cannot index by given value.", argv0, istr);
process::exit(65); // sysexits(3) EX_DATAERR
exit(64); // sysexits(3) EX_USAGE
},
};
}
@ -75,7 +75,7 @@ fn main() {
match valiter.peek() {
Some(_) => {
eprintln!("{}: {}: Not a table.", argv0, item);
process::exit(65); // sysexits(3) EX_DATAERR
exit(65); // sysexits(3) EX_DATAERR
},
None => {
match array.get(index) {
@ -86,7 +86,7 @@ fn main() {
eprintln!(
"{}: {:?}: No value at given index.", argv0, index
);
process::exit(65); // sysexits(3) EX_DATAERR
exit(65); // sysexits(3) EX_DATAERR
},
};
},
@ -94,7 +94,7 @@ fn main() {
eprintln!(
"{}: {:?}: No value at given index.", argv0, index
);
process::exit(65); // sysexits(3) EX_DATAERR
exit(65); // sysexits(3) EX_DATAERR
},
};
},
@ -108,7 +108,7 @@ fn main() {
match valiter.peek() {
Some(_) => {
eprintln!("{}: {}: Not a table.", argv0, item);
process::exit(65); // sysexits(3) EX_DATAERR
exit(65); // sysexits(3) EX_DATAERR
},
None => out.push_str(string.as_str()),
};
@ -125,7 +125,7 @@ fn main() {
},
None => {
eprintln!("{}: {}: No such table or key.", argv0, item);
process::exit(65); // sysexits(3) EX_DATAERR
exit(65); // sysexits(3) EX_DATAERR
},
};
}