mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
rust: Add rust detection to configure and a target to add binaries
We detect whether we have the rust tooling available (mainly `cargo`) and enable or disable the rust libraries, plugins and examples when it is enabled. Since the rest of the Makefiles assumes that executables have an associated header and C source file, we also needed to add a target that we can add non-C binaries to.
This commit is contained in:
parent
3c32f7d8f6
commit
7fdad0a60c
3 changed files with 34 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -64,3 +64,7 @@ doc/lightning*.[1578]
|
|||
# Ignore unrelated stuff
|
||||
.DS_Store
|
||||
.gdb_history
|
||||
|
||||
# Rust targets
|
||||
target
|
||||
Cargo.lock
|
16
Makefile
16
Makefile
|
@ -230,6 +230,8 @@ ALL_TEST_PROGRAMS :=
|
|||
ALL_FUZZ_TARGETS :=
|
||||
ALL_C_SOURCES :=
|
||||
ALL_C_HEADERS := header_versions_gen.h version_gen.h
|
||||
# Extra (non C) targets that should be built by default.
|
||||
DEFAULT_TARGETS :=
|
||||
|
||||
CPPFLAGS += -DBINTOPKGLIBEXECDIR="\"$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))\""
|
||||
CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I/usr/local/include $(SQLITE3_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) -DBUILD_ELEMENTS=1
|
||||
|
@ -260,7 +262,7 @@ ifeq ($(HAVE_POSTGRES),1)
|
|||
LDLIBS += $(POSTGRES_LDLIBS)
|
||||
endif
|
||||
|
||||
default: show-flags all-programs all-test-programs doc-all
|
||||
default: show-flags all-programs all-test-programs doc-all default-targets
|
||||
|
||||
ifneq ($(SUPPRESS_GENERATION),1)
|
||||
FORCE = FORCE
|
||||
|
@ -323,6 +325,13 @@ endif
|
|||
$(call VERBOSE,"printgen $@",tools/generate-wire.py -s -P --page impl $($@_args) ${@:.c=.h} `basename $< .csv | sed 's/_exp_/_/'` < $< > $@ && $(call SHA256STAMP,//,)); \
|
||||
fi
|
||||
|
||||
RUST_PROFILE ?= debug
|
||||
ifneq ($(RUST_PROFILE),debug)
|
||||
CARGO_OPTS := --profile=$(RUST_PROFILE) --quiet
|
||||
else
|
||||
CARGO_OPTS := --quiet
|
||||
endif
|
||||
|
||||
include external/Makefile
|
||||
include bitcoin/Makefile
|
||||
include common/Makefile
|
||||
|
@ -345,6 +354,9 @@ include contrib/libhsmd_python/Makefile
|
|||
ifneq ($(FUZZING),0)
|
||||
include tests/fuzz/Makefile
|
||||
endif
|
||||
ifneq ($(RUST),0)
|
||||
# Add Rust Makefiles here
|
||||
endif
|
||||
|
||||
# We make pretty much everything depend on these.
|
||||
ALL_GEN_HEADERS := $(filter %gen.h,$(ALL_C_HEADERS))
|
||||
|
@ -607,6 +619,7 @@ update-ccan:
|
|||
# Now ALL_PROGRAMS is fully populated, we can expand it.
|
||||
all-programs: $(ALL_PROGRAMS)
|
||||
all-test-programs: $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS)
|
||||
default-targets: $(DEFAULT_TARGETS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) ccan/config.h config.vars
|
||||
|
@ -630,6 +643,7 @@ clean: obsclean
|
|||
find . -name '*gcda' -delete
|
||||
find . -name '*gcno' -delete
|
||||
find . -name '*.nccout' -delete
|
||||
if [ "${RUST}" -eq "1" ]; then cargo clean; fi
|
||||
|
||||
# These must both be enabled for update-mocks
|
||||
ifeq ($(DEVELOPER)$(EXPERIMENTAL_FEATURES),11)
|
||||
|
|
15
configure
vendored
15
configure
vendored
|
@ -109,6 +109,15 @@ default_valgrind_setting()
|
|||
fi
|
||||
}
|
||||
|
||||
default_rust_setting()
|
||||
{
|
||||
if cargoa --version > /dev/null 2>&1; then
|
||||
echo 1
|
||||
else
|
||||
echo 0
|
||||
fi
|
||||
}
|
||||
|
||||
set_defaults()
|
||||
{
|
||||
# Default values, loaded from environment or canned.
|
||||
|
@ -129,6 +138,7 @@ set_defaults()
|
|||
VALGRIND=${VALGRIND:-$(default_valgrind_setting)}
|
||||
TEST_NETWORK=${TEST_NETWORK:-regtest}
|
||||
FUZZING=${FUZZING:-0}
|
||||
RUST=${RUST:-$(default_rust_setting)}
|
||||
}
|
||||
|
||||
usage()
|
||||
|
@ -167,6 +177,8 @@ usage()
|
|||
usage_with_default "--enable/disable-ub-sanitizer" "$UBSAN" "enable" "disable"
|
||||
echo " Compile with undefined behaviour sanitizer"
|
||||
usage_with_default "--enable/disable-fuzzing" "$FUZZING" "enable" "disable"
|
||||
echo " Compile with Rust support"
|
||||
usage_with_default "--enable/disable-rust" "$RUST" "enable" "disable"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -222,6 +234,8 @@ for opt in "$@"; do
|
|||
--disable-ub-sanitize) UBSAN=0;;
|
||||
--enable-fuzzing) FUZZING=1;;
|
||||
--disable-fuzzing) FUZZING=0;;
|
||||
--enable-rust) RUST=1;;
|
||||
--disable-rust) RUST=0;;
|
||||
--help|-h) usage;;
|
||||
*)
|
||||
echo "Unknown option '$opt'" >&2
|
||||
|
@ -430,6 +444,7 @@ add_var TEST_NETWORK "$TEST_NETWORK"
|
|||
add_var HAVE_PYTHON3_MAKO "$HAVE_PYTHON3_MAKO"
|
||||
add_var SHA256SUM "$SHA256SUM"
|
||||
add_var FUZZING "$FUZZING"
|
||||
add_var RUST "$RUST"
|
||||
|
||||
# Hack to avoid sha256 name clash with libwally: will be fixed when that
|
||||
# becomes a standalone shared lib.
|
||||
|
|
Loading…
Add table
Reference in a new issue