diff --git a/.gitignore b/.gitignore index 27788bc56..75d85c97c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ /target/ /tmp/ /busybox/ +/deps/target/ *~ .*.swp .*.swo +Cargo.lock diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index d9d1aa73d..000000000 --- a/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "deps/rust-crypto"] - path = deps/rust-crypto - url = https://github.com/DaGenix/rust-crypto -[submodule "deps/time"] - path = deps/time - url = https://github.com/rust-lang/time -[submodule "deps/regex"] - path = deps/regex - url = https://github.com/rust-lang/regex diff --git a/Makefile b/Makefile index 930b45587..750bfbc5e 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,22 @@ TEST ?= $(TEST_PROGS) TESTS := \ $(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS))))) +# figure out what dependencies we need based on which programs we're building +define DEP_INCLUDE +-include $(SRCDIR)/$(1)/deps.mk +endef +# we always depend on libc because common/util does +DEPLIBS := libc +DEPPLUGS := +# now, add in deps in src/utilname/deps.mk +$(foreach build,$(sort $(EXES) $(TESTS)),$(eval $(call DEP_INCLUDE,$(build)))) +# uniqify deps +DEPLIBS := $(sort $(DEPLIBS)) +DEPPLUGS := $(sort $(DEPPLUGS)) +# build --extern commandline for rustc +DEP_EXTERN := $(foreach lib,$(subst -,_,$(DEPLIBS)),--extern $(lib)=$(BUILDDIR)/lib$(lib).rlib) +DEP_EXTERN += $(foreach plug,$(subst -,_,$(DEPPLUGS)),--extern $(plug)=$(BUILDDIR)/lib$(plug).$(DYLIB_EXT)) + # Setup for building crates define BUILD_SETUP X := $(shell $(RUSTC) --print file-names --crate-type rlib $(SRCDIR)/$(1)/$(1).rs) @@ -187,6 +203,7 @@ $(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate)))) EXES_PATHS := $(addprefix $(BUILDDIR)/,$(EXES)) RLIB_PATHS := $(addprefix $(BUILDDIR)/,$(CRATE_RLIBS)) command = sh -c '$(1)' +RESERVED_EXTERNS := --extern uufalse=$(BUILDDIR)/libfalse.rlib --extern uutrue=$(BUILDDIR)/libtrue.rlib --extern uutest=$(BUILDDIR)/libtest.rlib # Main exe build rule define EXE_BUILD @@ -194,15 +211,26 @@ $(BUILDDIR)/gen/$(1).rs: $(BUILDDIR)/mkmain $(BUILDDIR)/mkmain $(1) $$@ $(BUILDDIR)/$(1): $(BUILDDIR)/gen/$(1).rs $(BUILDDIR)/$($(1)_RLIB) | $(BUILDDIR) deps - $(RUSTC) $(RUSTCBINFLAGS) --extern test=$(BUILDDIR)/libtest.rlib -o $$@ $$< + $(RUSTC) $(RUSTCBINFLAGS) $(RESERVED_EXTERNS) -o $$@ $$< $(if $(ENABLE_STRIP),strip $$@,) endef +# GRRR rust-crypto makes a crate called "crypto". +# This should NOT be allowed by crates.io. GRRRR. +define DEP_BUILD +DEP_$(1): +ifeq ($(1),crypto) + cd $(BASEDIR)/deps && $(CARGO) build --package rust-crypto --release +else + cd $(BASEDIR)/deps && $(CARGO) build --package $(1) --release +endif +endef + define CRATE_BUILD -include $(BUILDDIR)/$(1).d $(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps - $(RUSTC) $(RUSTCLIBFLAGS) --extern libc=$(BUILDDIR)/liblibc.rlib --extern time=$(BUILDDIR)/libtime.rlib --extern rand=$(BUILDDIR)/librand.rlib --extern regex=$(BUILDDIR)/libregex.rlib --extern serialize=$(BUILDDIR)/librustc_serialize.rlib --crate-type rlib --emit link,dep-info $$< --out-dir $(BUILDDIR) + $(RUSTC) $(RUSTCLIBFLAGS) $(DEP_EXTERN) --crate-type rlib --emit link,dep-info $$< --out-dir $(BUILDDIR) endef # Aliases build rule @@ -224,7 +252,7 @@ test_$(1): $(TEMPDIR)/$(1)/$(1)_test $(BUILDDIR)/$(1) $(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<) $(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1) - $(call command,$(RUSTC) $(RUSTCTESTFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --test -o $$@ $$<) + $(call command,$(RUSTC) $(RUSTCTESTFLAGS) $(DEP_EXTERN) --test -o $$@ $$<) $(TEMPDIR)/$(1): | $(TEMPDIR) $(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@) @@ -238,11 +266,12 @@ $(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate)))) $(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe)))) $(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias)))) $(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test)))) +$(foreach dep,$(sort $(DEPLIBS) $(DEPPLUGS)),$(eval $(call DEP_BUILD,$(dep)))) -include $(BUILDDIR)/uutils.d $(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS) $(BUILDDIR)/mkuutils $(BUILDDIR)/gen/uutils.rs $(EXES) - $(RUSTC) $(RUSTCBINFLAGS) --extern test=$(BUILDDIR)/libtest.rlib --emit link,dep-info $(BUILDDIR)/gen/uutils.rs --out-dir $(BUILDDIR) + $(RUSTC) $(RUSTCBINFLAGS) $(RESERVED_EXTERNS) --emit link,dep-info $(BUILDDIR)/gen/uutils.rs --out-dir $(BUILDDIR) $(if $(ENABLE_STRIP),strip $@) # Library for stdbuf @@ -255,26 +284,9 @@ $(BUILDDIR)/libstdbuf.$(DYLIB_EXT): $(SRCDIR)/stdbuf/libstdbuf.rs $(SRCDIR)/stdb $(BUILDDIR)/stdbuf: $(BUILDDIR)/libstdbuf.$(DYLIB_EXT) -# Dependencies -$(BUILDDIR)/.rust-crypto: | $(BUILDDIR) - cd $(BASEDIR)/deps/rust-crypto && $(CARGO) build --release - cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/librand*.rlib $(BUILDDIR)/librand.rlib - cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/librustc_serialize*.rlib $(BUILDDIR)/librustc_serialize.rlib - cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/libtime*.rlib $(BUILDDIR)/libtime.rlib - cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/liblibc*.rlib $(BUILDDIR)/liblibc.rlib - cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib - @touch $@ - -#$(BUILDDIR)/.rust-time: | $(BUILDDIR) -# cd $(BASEDIR)/deps/time && $(CARGO) build --release -# cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib -# @touch $@ - -$(BUILDDIR)/.rust-regex: | $(BUILDDIR) - cd $(BASEDIR)/deps/regex/regex_macros && $(CARGO) build --release - cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/libregex_macros* $(BUILDDIR) - cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/deps/libregex*.rlib $(BUILDDIR)/libregex.rlib - @touch $@ +deps: $(BUILDDIR) $(SRCDIR)/cksum/crc_table.rs $(addprefix DEP_,$(DEPLIBS) $(DEPPLUGS)) + $(foreach lib,$(subst -,_,$(DEPLIBS)),$(shell cp $(BASEDIR)/deps/target/release/deps/lib$(lib)-*.rlib $(BUILDDIR)/lib$(lib).rlib)) + $(foreach plug,$(subst -,_,$(DEPPLUGS)),$(shell cp $(BASEDIR)/deps/target/release/deps/lib$(plug)-*.$(DYLIB_EXT) $(BUILDDIR)/lib$(plug).$(DYLIB_EXT))) $(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR) $(RUSTC) $(RUSTCFLAGS) $< -o $@ @@ -285,8 +297,6 @@ $(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR) $(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCBINFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table -deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs - crates: echo $(EXES) @@ -294,10 +304,12 @@ test: $(TEMPDIR) $(addprefix test_,$(TESTS)) $(RM) -rf $(TEMPDIR) clean: - $(RM) -rf $(BUILDDIR) $(TEMPDIR) $(BASEDIR)/deps/time/target + $(RM) -rf $(BUILDDIR) $(TEMPDIR) + +distclean: clean + cd $(BASEDIR)/deps && $(CARGO) clean $(BUILDDIR): - git submodule update --init mkdir -p $(BUILDDIR)/gen $(TEMPDIR): @@ -356,4 +368,4 @@ busytest: $(BUILDDIR)/busybox $(BUILDDIR)/.config (cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS)) endif -.PHONY: $(TEMPDIR) all deps test clean busytest install uninstall +.PHONY: $(TEMPDIR) all deps test distclean clean busytest install uninstall diff --git a/deps/Cargo.toml b/deps/Cargo.toml new file mode 100644 index 000000000..622eef41d --- /dev/null +++ b/deps/Cargo.toml @@ -0,0 +1,16 @@ +[project] +name = "deps" +version = "0.0.0" + +[lib] +name = "null" + +[dependencies] +libc = "0.1.6" +rand = "0.3.8" +regex = "0.1.30" +regex_macros = "0.1.17" +rust-crypto = "0.2.31" +rustc-serialize = "0.3.13" +time = "0.1.25" +unicode-width = "0.1.1" diff --git a/deps/regex b/deps/regex deleted file mode 160000 index 399758aea..000000000 --- a/deps/regex +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 399758aeae3dcab382b0af5fa9964c1e32066dda diff --git a/deps/rust-crypto b/deps/rust-crypto deleted file mode 160000 index 5571cb416..000000000 --- a/deps/rust-crypto +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5571cb41690b9cee12025192393ea7df0eddc21b diff --git a/deps/time b/deps/time deleted file mode 160000 index a7869dcee..000000000 --- a/deps/time +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a7869dcee07de6df4e81b48bdfe137c70c153643 diff --git a/mkmain.rs b/mkmain.rs index 652c7193e..9eed243fd 100644 --- a/mkmain.rs +++ b/mkmain.rs @@ -23,7 +23,12 @@ fn main() { return; } - let crat = &args[1][..]; + let crat = match &args[1][..] { + "false" => "uufalse", + "test" => "uutest", + "true" => "uutrue", + _ => &args[1][..], + }; let outfile = &args[2][..]; let main = TEMPLATE.replace("@UTIL_CRATE@", crat); diff --git a/mkuutils.rs b/mkuutils.rs index 7e9de8207..48f167360 100644 --- a/mkuutils.rs +++ b/mkuutils.rs @@ -29,9 +29,15 @@ fn main() { util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n"); hashsum = true; } - } - "true" => util_map.push_str("fn uutrue(_: Vec) -> i32 { 0 }\nmap.insert(\"true\", uutrue);\n"), - "false" => util_map.push_str("fn uufalse(_: Vec) -> i32 { 1 }\nmap.insert(\"false\", uufalse);\n"), + }, + "true" => { + util_map.push_str("fn uutrue(_: Vec) -> i32 { 0 }\n"); + util_map.push_str("map.insert(\"true\", uutrue as fn(Vec) -> i32);\n"); + }, + "false" => { + util_map.push_str("fn uufalse(_: Vec) -> i32 { 1 }\n"); + util_map.push_str("map.insert(\"false\", uufalse as fn(Vec) -> i32);\n"); + }, _ => { crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]); util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec) -> i32);\n", prog = prog))[..]); diff --git a/src/base64/base64.rs b/src/base64/base64.rs index a6b77a807..f75d70bda 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -10,7 +10,7 @@ * that was distributed with this source code. */ -extern crate serialize; +extern crate rustc_serialize as serialize; extern crate getopts; extern crate libc; #[macro_use] extern crate log; diff --git a/src/base64/deps.mk b/src/base64/deps.mk new file mode 100644 index 000000000..5f486e20e --- /dev/null +++ b/src/base64/deps.mk @@ -0,0 +1 @@ +DEPLIBS += rustc-serialize diff --git a/src/chmod/deps.mk b/src/chmod/deps.mk new file mode 100644 index 000000000..fbf77a3ce --- /dev/null +++ b/src/chmod/deps.mk @@ -0,0 +1,2 @@ +DEPLIBS += regex +DEPPLUGS += regex_macros diff --git a/src/cksum/gen_table.rs b/src/cksum/gen_table.rs index 5a2239c01..b8b9b62e4 100644 --- a/src/cksum/gen_table.rs +++ b/src/cksum/gen_table.rs @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -use std::fs::OpenOptions; +use std::fs::File; use std::io::Write; static CRC_TABLE_LEN: usize = 256; @@ -18,10 +18,10 @@ fn main() { for num in (0 .. CRC_TABLE_LEN) { table.push(crc_entry(num as u8) as u32); } - let file = OpenOptions::new().truncate(true).write(true).open("crc_table.rs").ok().unwrap(); + let file = File::create("crc_table.rs").unwrap_or_else(|e| panic!("{}", e)); write!(&file, "/* auto-generated (DO NOT EDIT) */ -pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table); +pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table).unwrap(); } #[inline] diff --git a/src/du/deps.mk b/src/du/deps.mk new file mode 100644 index 000000000..b6534caec --- /dev/null +++ b/src/du/deps.mk @@ -0,0 +1 @@ +DEPLIBS += time diff --git a/src/fmt/deps.mk b/src/fmt/deps.mk new file mode 100644 index 000000000..fb8005c0c --- /dev/null +++ b/src/fmt/deps.mk @@ -0,0 +1 @@ +DEPLIBS += unicode-width diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index 11c5a8867..a20047278 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -9,11 +9,12 @@ * file that was distributed with this source code. */ -#![feature(box_syntax,core,rustc_private,collections,str_char,unicode,str_words)] +#![feature(box_syntax,core,rustc_private,collections,str_char,unicode)] extern crate core; extern crate getopts; -extern crate unicode; +extern crate rustc_unicode; +extern crate unicode_width; use std::cmp; use std::io::{Read, BufReader, BufWriter}; diff --git a/src/fmt/linebreak.rs b/src/fmt/linebreak.rs index 28887b3e0..c4394baf9 100644 --- a/src/fmt/linebreak.rs +++ b/src/fmt/linebreak.rs @@ -10,7 +10,6 @@ use FmtOptions; use parasplit::{Paragraph, ParaWords, WordInfo}; use std::io::{Write, BufWriter, Stdout}; -use std::num::{Float, Int, SignedInt}; use std::i64; use std::cmp; use std::mem; @@ -373,7 +372,7 @@ fn compute_demerits(delta_len: isize, stretch: isize, wlen: isize, prev_rat: f32 // we penalize lines that have very different ratios from previous lines let bad_delta_r = (DR_MULT * (((ratio - prev_rat) / 2.0).powf(3f32)).abs()) as i64; - let demerits = Int::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2); + let demerits = i64::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2); (demerits, ratio) } diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 1cf446fd1..22c688585 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -11,7 +11,8 @@ use core::iter::Peekable; use std::io::{BufRead, Lines}; use std::slice::Iter; use std::str::CharRange; -use unicode::str::UnicodeStr; +use rustc_unicode::str::UnicodeStr; +use unicode_width::UnicodeWidthChar; use FileOrStdReader; use FmtOptions; @@ -25,7 +26,7 @@ fn char_width(c: char) -> usize { // otherwise, get the unicode width // note that we shouldn't actually get None here because only c < 0xA0 // can return None, but for safety and future-proofing we do it this way - c.width(false).unwrap_or(1) + UnicodeWidthChar::width(c).unwrap_or(1) } } @@ -415,7 +416,7 @@ impl<'a> ParaWords<'a> { // no extra spacing for mail headers; always exactly 1 space // safe to trim_left on every line of a mail header, since the // first line is guaranteed not to have any spaces - self.words.extend(self.para.lines.iter().flat_map(|x| x.words()).map(|x| WordInfo { + self.words.extend(self.para.lines.iter().flat_map(|x| x.split_whitespace()).map(|x| WordInfo { word : x, word_start : 0, word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped) diff --git a/src/hashsum/deps.mk b/src/hashsum/deps.mk new file mode 100644 index 000000000..2cb0e2615 --- /dev/null +++ b/src/hashsum/deps.mk @@ -0,0 +1 @@ +DEPLIBS += regex crypto rand rustc-serialize time diff --git a/src/nl/deps.mk b/src/nl/deps.mk new file mode 100644 index 000000000..fbf77a3ce --- /dev/null +++ b/src/nl/deps.mk @@ -0,0 +1,2 @@ +DEPLIBS += regex +DEPPLUGS += regex_macros diff --git a/src/touch/deps.mk b/src/touch/deps.mk new file mode 100644 index 000000000..b6534caec --- /dev/null +++ b/src/touch/deps.mk @@ -0,0 +1 @@ +DEPLIBS += time diff --git a/src/uptime/deps.mk b/src/uptime/deps.mk new file mode 100644 index 000000000..b6534caec --- /dev/null +++ b/src/uptime/deps.mk @@ -0,0 +1 @@ +DEPLIBS += time diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index aecfb2dc5..c6a4a1845 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -16,7 +16,7 @@ extern crate getopts; extern crate libc; -extern crate "time" as rtime; +extern crate time as rtime; use std::ffi::CString; use std::mem::transmute;