Skip to content

Commit 7fdad0a

Browse files
committed
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.
1 parent 3c32f7d commit 7fdad0a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ doc/lightning*.[1578]
6464
# Ignore unrelated stuff
6565
.DS_Store
6666
.gdb_history
67+
68+
# Rust targets
69+
target
70+
Cargo.lock

Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ ALL_TEST_PROGRAMS :=
230230
ALL_FUZZ_TARGETS :=
231231
ALL_C_SOURCES :=
232232
ALL_C_HEADERS := header_versions_gen.h version_gen.h
233+
# Extra (non C) targets that should be built by default.
234+
DEFAULT_TARGETS :=
233235

234236
CPPFLAGS += -DBINTOPKGLIBEXECDIR="\"$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))\""
235237
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)
260262
LDLIBS += $(POSTGRES_LDLIBS)
261263
endif
262264

263-
default: show-flags all-programs all-test-programs doc-all
265+
default: show-flags all-programs all-test-programs doc-all default-targets
264266

265267
ifneq ($(SUPPRESS_GENERATION),1)
266268
FORCE = FORCE
@@ -323,6 +325,13 @@ endif
323325
$(call VERBOSE,"printgen $@",tools/generate-wire.py -s -P --page impl $($@_args) ${@:.c=.h} `basename $< .csv | sed 's/_exp_/_/'` < $< > $@ && $(call SHA256STAMP,//,)); \
324326
fi
325327

328+
RUST_PROFILE ?= debug
329+
ifneq ($(RUST_PROFILE),debug)
330+
CARGO_OPTS := --profile=$(RUST_PROFILE) --quiet
331+
else
332+
CARGO_OPTS := --quiet
333+
endif
334+
326335
include external/Makefile
327336
include bitcoin/Makefile
328337
include common/Makefile
@@ -345,6 +354,9 @@ include contrib/libhsmd_python/Makefile
345354
ifneq ($(FUZZING),0)
346355
include tests/fuzz/Makefile
347356
endif
357+
ifneq ($(RUST),0)
358+
# Add Rust Makefiles here
359+
endif
348360

349361
# We make pretty much everything depend on these.
350362
ALL_GEN_HEADERS := $(filter %gen.h,$(ALL_C_HEADERS))
@@ -607,6 +619,7 @@ update-ccan:
607619
# Now ALL_PROGRAMS is fully populated, we can expand it.
608620
all-programs: $(ALL_PROGRAMS)
609621
all-test-programs: $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS)
622+
default-targets: $(DEFAULT_TARGETS)
610623

611624
distclean: clean
612625
$(RM) ccan/config.h config.vars
@@ -630,6 +643,7 @@ clean: obsclean
630643
find . -name '*gcda' -delete
631644
find . -name '*gcno' -delete
632645
find . -name '*.nccout' -delete
646+
if [ "${RUST}" -eq "1" ]; then cargo clean; fi
633647

634648
# These must both be enabled for update-mocks
635649
ifeq ($(DEVELOPER)$(EXPERIMENTAL_FEATURES),11)

configure

+15
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ default_valgrind_setting()
109109
fi
110110
}
111111

112+
default_rust_setting()
113+
{
114+
if cargoa --version > /dev/null 2>&1; then
115+
echo 1
116+
else
117+
echo 0
118+
fi
119+
}
120+
112121
set_defaults()
113122
{
114123
# Default values, loaded from environment or canned.
@@ -129,6 +138,7 @@ set_defaults()
129138
VALGRIND=${VALGRIND:-$(default_valgrind_setting)}
130139
TEST_NETWORK=${TEST_NETWORK:-regtest}
131140
FUZZING=${FUZZING:-0}
141+
RUST=${RUST:-$(default_rust_setting)}
132142
}
133143

134144
usage()
@@ -167,6 +177,8 @@ usage()
167177
usage_with_default "--enable/disable-ub-sanitizer" "$UBSAN" "enable" "disable"
168178
echo " Compile with undefined behaviour sanitizer"
169179
usage_with_default "--enable/disable-fuzzing" "$FUZZING" "enable" "disable"
180+
echo " Compile with Rust support"
181+
usage_with_default "--enable/disable-rust" "$RUST" "enable" "disable"
170182
exit 1
171183
}
172184

@@ -222,6 +234,8 @@ for opt in "$@"; do
222234
--disable-ub-sanitize) UBSAN=0;;
223235
--enable-fuzzing) FUZZING=1;;
224236
--disable-fuzzing) FUZZING=0;;
237+
--enable-rust) RUST=1;;
238+
--disable-rust) RUST=0;;
225239
--help|-h) usage;;
226240
*)
227241
echo "Unknown option '$opt'" >&2
@@ -430,6 +444,7 @@ add_var TEST_NETWORK "$TEST_NETWORK"
430444
add_var HAVE_PYTHON3_MAKO "$HAVE_PYTHON3_MAKO"
431445
add_var SHA256SUM "$SHA256SUM"
432446
add_var FUZZING "$FUZZING"
447+
add_var RUST "$RUST"
433448

434449
# Hack to avoid sha256 name clash with libwally: will be fixed when that
435450
# becomes a standalone shared lib.

0 commit comments

Comments
 (0)