Skip to content

Commit d0f5fb7

Browse files
committed
Move the library code into its own crate
This change is mostly to prepare for adding debug logging to `sh`, but it has the side benefit of making the final executable slightly smaller as well as slightly improving compilation time (maybe we should split some of the utility modules into crates like in uutils/coreutils?).
1 parent 601d940 commit d0f5fb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+182
-87
lines changed

Cargo.lock

Lines changed: 30 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,43 @@ description = "A collection of utilities important to basic system functionality
66
autotests = false
77

88
[features]
9-
arch = ["platform-info"]
10-
base32 = ["uucore"]
11-
base64 = ["uucore"]
12-
yes = []
9+
arch = ["libmesabox/arch"]
10+
base32 = ["libmesabox/base32"]
11+
base64 = ["libmesabox/base64"]
12+
yes = ["libmesabox/yes"]
1313
gnu = [
1414
"arch",
1515
"base32",
1616
"base64",
1717
"yes"
1818
]
1919

20-
getty = ["libc"]
20+
getty = ["libmesabox/getty"]
2121
loginutils = [
2222
"getty"
2323
]
2424

25-
# XXX: temporary until renaming dependencies is supported
26-
tar_util = ["tar", "globset"]
25+
# FIXME: this is only like this because we can't rename dependencies and we use the same macro in
26+
# the tests that libmesabox uses to build
27+
tar_util = ["libmesabox/tar_util"]
2728
lsb = [
2829
"tar_util"
2930
]
3031

31-
ping = ["chrono", "crossbeam", "libc", "pnet", "byteorder", "trust-dns-resolver", "mio", "socket2"]
32+
ping = ["libmesabox/ping"]
3233
networking = [
3334
"ping"
3435
]
3536

36-
cat = []
37-
chmod = ["walkdir", "uucore"]
38-
echo = []
39-
false = []
40-
head = []
41-
sh = ["nom", "glob", "rustyline", "libc"]
42-
sleep = ["uucore"]
43-
true = []
44-
uname = ["platform-info"]
37+
cat = ["libmesabox/cat"]
38+
chmod = ["libmesabox/chmod"]
39+
echo = ["libmesabox/echo"]
40+
false = ["libmesabox/false"]
41+
head = ["libmesabox/head"]
42+
sh = ["libmesabox/sh"]
43+
sleep = ["libmesabox/sleep"]
44+
true = ["libmesabox/true"]
45+
uname = ["libmesabox/uname"]
4546
posix = [
4647
"cat",
4748
"chmod",
@@ -54,7 +55,7 @@ posix = [
5455
"uname"
5556
]
5657

57-
init = ["fnv", "libc"]
58+
init = ["libmesabox/init"]
5859
sysinit = [
5960
"init"
6061
]
@@ -66,7 +67,7 @@ unix = [
6667
"lsb",
6768
"networking",
6869
"posix",
69-
"sysinit",
70+
"sysinit"
7071
]
7172

7273
# utilities that work on Windows
@@ -84,41 +85,19 @@ windows = [
8485

8586
# the following are real features (rather than utilities)
8687
# used to prioritize latency over throughput in utilites that care
87-
latency = []
88+
latency = ["libmesabox/latency"]
8889
# use dynamic dispatch rather than static dispatch (makes utilities slower, but sometimes smaller
8990
# as well). this is preferred to no-dynamic if both are specified
90-
full-dynamic = []
91+
full-dynamic = ["libmesabox/full-dynamic"]
9192
# only use static dispatch (this will lead to dramatically larger compile times and binary sizes)
92-
no-dynamic = []
93+
no-dynamic = ["libmesabox/no-dynamic"]
9394

9495
default = ["unix"]
9596

97+
[workspace]
98+
9699
[dependencies]
97-
clap = "2.31.2"
98-
failure = "0.1.1"
99-
failure_derive = "0.1.1"
100-
kernel32-sys = "0.2.2"
101-
winapi = { version = "0.3.5", features = ["namedpipeapi"] }
102-
nix = "0.10.0"
103-
104-
libc = { version = "0.2.40", optional = true }
105-
platform-info = { git = "https://github.com/uutils/platform-info", optional = true }
106-
uucore = { git = "https://github.com/uutils/coreutils", features = ["encoding", "fs", "mode", "parse_time"], optional = true }
107-
tar = { version = "0.4.15", optional = true }
108-
globset = { version = "0.4.0", optional = true }
109-
glob = { git = "https://github.com/mesalock-linux/glob", optional = true }
110-
chrono = { version = "0.4.2", optional = true }
111-
crossbeam = { version = "0.3.2", optional = true }
112-
pnet = { version = "0.21.0", optional = true }
113-
byteorder = { version = "1.2.3", optional = true }
114-
trust-dns-resolver = { version = "0.9.0", optional = true }
115-
mio = { version = "0.6.14", optional = true }
116-
socket2 = { version = "0.3.5", optional = true }
117-
walkdir = { version = "2.1.4", optional = true }
118-
fnv = { version = "1.0.6", optional = true }
119-
nom = { version = "4.0.0", features = ["verbose-errors"], optional = true }
120-
#rustyline = { version = "1.0.0", optional = true }
121-
rustyline = { git = "https://github.com/kkawakam/rustyline", optional = true }
100+
libmesabox = { path = "libmesabox" }
122101

123102
[dev-dependencies]
124103
tempfile = "3.0.2"

examples/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extern crate mesabox;
1+
extern crate libmesabox as mesabox;
22

33
use mesabox::UtilData;
44
use std::io::Write;

libmesabox/Cargo.toml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
[package]
2+
name = "libmesabox"
3+
version = "0.1.0"
4+
authors = ["Alex Lyon <[email protected]>"]
5+
description = "A collection of common command-line utilities in library form"
6+
7+
[features]
8+
arch = ["platform-info"]
9+
base32 = ["uucore"]
10+
base64 = ["uucore"]
11+
yes = []
12+
gnu = [
13+
"arch",
14+
"base32",
15+
"base64",
16+
"yes"
17+
]
18+
19+
getty = ["libc"]
20+
loginutils = [
21+
"getty"
22+
]
23+
24+
# XXX: temporary until renaming dependencies is supported
25+
tar_util = ["tar", "globset"]
26+
lsb = [
27+
"tar"
28+
]
29+
30+
ping = ["chrono", "crossbeam", "libc", "pnet", "byteorder", "trust-dns-resolver", "mio", "socket2"]
31+
networking = [
32+
"ping"
33+
]
34+
35+
cat = []
36+
chmod = ["walkdir", "uucore"]
37+
echo = []
38+
false = []
39+
head = []
40+
sh = ["nom", "glob", "rustyline", "libc"]
41+
sleep = ["uucore"]
42+
true = []
43+
uname = ["platform-info"]
44+
posix = [
45+
"cat",
46+
"chmod",
47+
"echo",
48+
"false",
49+
"head",
50+
"sh",
51+
"sleep",
52+
"true",
53+
"uname"
54+
]
55+
56+
init = ["fnv", "libc"]
57+
sysinit = [
58+
"init"
59+
]
60+
61+
# utilities that work on Unix
62+
unix = [
63+
"gnu",
64+
"loginutils",
65+
"lsb",
66+
"networking",
67+
"posix",
68+
"sysinit",
69+
]
70+
71+
# utilities that work on Windows
72+
windows = [
73+
"gnu",
74+
75+
"cat",
76+
"echo",
77+
"false",
78+
"head",
79+
"sleep",
80+
"true",
81+
"uname"
82+
]
83+
84+
# the following are real features (rather than utilities)
85+
# used to prioritize latency over throughput in utilites that care
86+
latency = []
87+
# use dynamic dispatch rather than static dispatch (makes utilities slower, but sometimes smaller
88+
# as well). this is preferred to no-dynamic if both are specified
89+
full-dynamic = []
90+
# only use static dispatch (this will lead to dramatically larger compile times and binary sizes)
91+
no-dynamic = []
92+
93+
default = ["unix"]
94+
95+
[dependencies]
96+
clap = "2.31.2"
97+
failure = "0.1.1"
98+
failure_derive = "0.1.1"
99+
kernel32-sys = "0.2.2"
100+
winapi = { version = "0.3.5", features = ["namedpipeapi"] }
101+
nix = "0.10.0"
102+
103+
libc = { version = "0.2.40", optional = true }
104+
platform-info = { git = "https://github.com/uutils/platform-info", optional = true }
105+
uucore = { git = "https://github.com/uutils/coreutils", features = ["encoding", "fs", "mode", "parse_time"], optional = true }
106+
tar = { version = "0.4.15", optional = true }
107+
globset = { version = "0.4.0", optional = true }
108+
glob = { git = "https://github.com/mesalock-linux/glob", optional = true }
109+
chrono = { version = "0.4.2", optional = true }
110+
crossbeam = { version = "0.3.2", optional = true }
111+
pnet = { version = "0.21.0", optional = true }
112+
byteorder = { version = "1.2.3", optional = true }
113+
trust-dns-resolver = { version = "0.9.0", optional = true }
114+
mio = { version = "0.6.14", optional = true }
115+
socket2 = { version = "0.3.5", optional = true }
116+
walkdir = { version = "2.1.4", optional = true }
117+
fnv = { version = "1.0.6", optional = true }
118+
nom = { version = "4.0.0", features = ["verbose-errors"], optional = true }
119+
#rustyline = { version = "1.0.0", optional = true }
120+
rustyline = { git = "https://github.com/kkawakam/rustyline", optional = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/posix/sh/env.rs renamed to libmesabox/src/posix/sh/env.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ impl Environment {
300300
&self.fds[fd]
301301
}
302302

303-
pub fn get_fd_mut(&mut self, fd: usize) -> &mut EnvFd {
304-
&mut self.fds[fd]
305-
}
306-
307303
pub fn fds(&self) -> &FdArray {
308304
&self.fds
309305
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/posix/sh/types/scoped_array.rs renamed to libmesabox/src/posix/sh/types/scoped_array.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::iter::IntoIterator;
2-
use std::ops::{Index, IndexMut};
2+
use std::ops::Index;
33
use std::slice;
44

55
use super::{Locality, Scoped};
@@ -24,8 +24,6 @@ impl<T: FixedArray<Item = Locality<V>>, V> ScopedArray<T, V> {
2424
}
2525
}
2626

27-
// XXX: do we really want to implement this? this allows stuff like arr[idx] = val to work, which
28-
// will end up ignoring Locality::set_val()
2927
impl<T: FixedArray<Item = Locality<V>>, V> ScopedArray<T, V> {
3028
pub fn iter_mut(&mut self) -> ScopedArrayIter<V> {
3129
ScopedArrayIter {
@@ -65,12 +63,6 @@ impl<T: FixedArray<Item = Locality<V>>, V> Index<usize> for ScopedArray<T, V> {
6563
}
6664
}
6765

68-
impl<T: FixedArray<Item = Locality<V>>, V> IndexMut<usize> for ScopedArray<T, V> {
69-
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
70-
self.inner.as_mut()[index].current_val_mut()
71-
}
72-
}
73-
7466
pub struct ScopedArrayIter<'a, V: 'a> {
7567
inner: IterMut<'a, Locality<V>>,
7668
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// For a copy, see the LICENSE file.
77
//
88

9-
extern crate mesabox;
9+
extern crate libmesabox as mesabox;
1010

1111
use mesabox::UtilData;
1212
use std::env;

tests/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// For a copy, see the LICENSE file.
77
//
88

9-
extern crate mesabox;
9+
extern crate libmesabox as mesabox;
1010
#[macro_use]
1111
extern crate lazy_static;
1212
extern crate libc;
@@ -16,7 +16,7 @@ mod util;
1616
#[macro_use]
1717
mod macros;
1818

19-
include!("../src/util/build/import.rs");
19+
include!("../libmesabox/src/util/build/import.rs");
2020

2121
macro_rules! generate_fns {
2222
($($group:ident { $(($util:tt, $feature:expr)),+ }),*) => {
@@ -25,4 +25,4 @@ macro_rules! generate_fns {
2525
}
2626

2727
// calls generate_fns!()
28-
include!("../src/util_list.rs");
28+
include!("../libmesabox/src/util_list.rs");

0 commit comments

Comments
 (0)