mirror of
https://github.com/uutils/coreutils
synced 2024-07-21 01:44:19 +00:00
dependency builds use Cargo
With this change, individual submodules can specify their dependencies with an additional file called "deps.mk" in the subdir. When building, only the dependencies that are necessary are built, using cargo, and then linked. This greatly simplifies adding new dependencies: add the package in deps/Cargo.toml, and add the appropriate line in "deps.mk" in the src/utilname/ directory, and the dependency will be built automatically as needed. This also removes the need to use git submodules.
This commit is contained in:
parent
c6585b7086
commit
d4f39e1638
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,6 +2,8 @@
|
|||
/target/
|
||||
/tmp/
|
||||
/busybox/
|
||||
/deps/target/
|
||||
*~
|
||||
.*.swp
|
||||
.*.swo
|
||||
Cargo.lock
|
||||
|
|
9
.gitmodules
vendored
9
.gitmodules
vendored
|
@ -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
|
70
Makefile
70
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
|
||||
|
|
16
deps/Cargo.toml
vendored
Normal file
16
deps/Cargo.toml
vendored
Normal file
|
@ -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"
|
1
deps/regex
vendored
1
deps/regex
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 399758aeae3dcab382b0af5fa9964c1e32066dda
|
1
deps/rust-crypto
vendored
1
deps/rust-crypto
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 5571cb41690b9cee12025192393ea7df0eddc21b
|
1
deps/time
vendored
1
deps/time
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit a7869dcee07de6df4e81b48bdfe137c70c153643
|
|
@ -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);
|
||||
|
|
12
mkuutils.rs
12
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<String>) -> i32 { 0 }\nmap.insert(\"true\", uutrue);\n"),
|
||||
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> i32 { 1 }\nmap.insert(\"false\", uufalse);\n"),
|
||||
},
|
||||
"true" => {
|
||||
util_map.push_str("fn uutrue(_: Vec<String>) -> i32 { 0 }\n");
|
||||
util_map.push_str("map.insert(\"true\", uutrue as fn(Vec<String>) -> i32);\n");
|
||||
},
|
||||
"false" => {
|
||||
util_map.push_str("fn uufalse(_: Vec<String>) -> i32 { 1 }\n");
|
||||
util_map.push_str("map.insert(\"false\", uufalse as fn(Vec<String>) -> 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<String>) -> i32);\n", prog = prog))[..]);
|
||||
|
|
|
@ -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;
|
||||
|
|
1
src/base64/deps.mk
Normal file
1
src/base64/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += rustc-serialize
|
2
src/chmod/deps.mk
Normal file
2
src/chmod/deps.mk
Normal file
|
@ -0,0 +1,2 @@
|
|||
DEPLIBS += regex
|
||||
DEPPLUGS += regex_macros
|
|
@ -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]
|
||||
|
|
1
src/du/deps.mk
Normal file
1
src/du/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += time
|
1
src/fmt/deps.mk
Normal file
1
src/fmt/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += unicode-width
|
|
@ -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};
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
1
src/hashsum/deps.mk
Normal file
1
src/hashsum/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += regex crypto rand rustc-serialize time
|
2
src/nl/deps.mk
Normal file
2
src/nl/deps.mk
Normal file
|
@ -0,0 +1,2 @@
|
|||
DEPLIBS += regex
|
||||
DEPPLUGS += regex_macros
|
1
src/touch/deps.mk
Normal file
1
src/touch/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += time
|
1
src/uptime/deps.mk
Normal file
1
src/uptime/deps.mk
Normal file
|
@ -0,0 +1 @@
|
|||
DEPLIBS += time
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue