mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +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
23 changed files with 97 additions and 57 deletions
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue