Skip to content

Commit 0de0867

Browse files
committed
github_workflows: install rust
Since we have introduced rust, it needs to be installed for the continuous integration build targets. Create an install script (build_rust.sh) that needs to be run as the same user that builds git. Because of the limitations of meson, create build_rust.sh which makes it easy to centralize how rust is built between meson and make. There are 2 interesting decisions worth calling out in this commit: * The 'output' field of custom_target() does not allow specifying a file nested inside the build directory. Thus create build_rust.sh to build rust with all of its parameters and then moves libxdiff.a to the root of the build directory. * Install curl, to facilitate the rustup install script. Signed-off-by: Ezekiel Newren <[email protected]>
1 parent 5a959c9 commit 0de0867

File tree

10 files changed

+173
-46
lines changed

10 files changed

+173
-46
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: [push, pull_request]
44

55
env:
66
DEVELOPER: 1
7+
RUST_VERSION: 1.87.0
78

89
# If more than one workflow run is triggered for the very same commit hash
910
# (which happens when multiple branches pointing to the same commit), only

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,4 @@ Release/
254254
/contrib/buildsystems/out
255255
/contrib/libgit-rs/target
256256
/contrib/libgit-sys/target
257+
/rust/target

Makefile

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,29 @@ TEST_SHELL_PATH = $(SHELL_PATH)
919919

920920
LIB_FILE = libgit.a
921921
XDIFF_LIB = xdiff/lib.a
922+
923+
EXTLIBS =
924+
922925
ifeq ($(DEBUG), 1)
923-
RUST_LIB = rust/target/debug/libxdiff.a
926+
RUST_BUILD_MODE = debug
924927
else
925-
RUST_LIB = rust/target/release/libxdiff.a
928+
RUST_BUILD_MODE = release
929+
endif
930+
931+
RUST_TARGET_DIR = rust/target/$(RUST_BUILD_MODE)
932+
RUST_FLAGS_FOR_C = -L$(RUST_TARGET_DIR)
933+
934+
.PHONY: compile_rust
935+
compile_rust:
936+
./build_rust.sh . $(RUST_BUILD_MODE) xdiff
937+
938+
EXTLIBS += ./$(RUST_TARGET_DIR)/libxdiff.a
939+
940+
UNAME_S := $(shell uname -s)
941+
ifeq ($(UNAME_S),Linux)
942+
EXTLIBS += -ldl
926943
endif
944+
927945
REFTABLE_LIB = reftable/libreftable.a
928946

929947
GENERATED_H += command-list.h
@@ -1395,9 +1413,7 @@ UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
13951413

13961414
# xdiff and reftable libs may in turn depend on what is in libgit.a
13971415
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
1398-
EXTLIBS =
13991416

1400-
GITLIBS += $(RUST_LIB)
14011417

14021418
GIT_USER_AGENT = git/$(GIT_VERSION)
14031419

@@ -2548,7 +2564,7 @@ git.sp git.s git.o: EXTRA_CPPFLAGS = \
25482564
'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
25492565
'-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
25502566

2551-
git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
2567+
git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS) compile_rust
25522568
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
25532569
$(filter %.o,$^) $(LIBS)
25542570

@@ -2898,17 +2914,17 @@ headless-git.o: compat/win32/headless.c GIT-CFLAGS
28982914
headless-git$X: headless-git.o git.res GIT-LDFLAGS
28992915
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -mwindows -o $@ $< git.res
29002916

2901-
git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
2917+
git-%$X: %.o GIT-LDFLAGS $(GITLIBS) compile_rust
29022918
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
29032919

2904-
git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
2920+
git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS) compile_rust
29052921
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29062922
$(IMAP_SEND_LDFLAGS) $(LIBS)
29072923

2908-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2924+
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS) compile_rust
29092925
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29102926
$(CURL_LIBCURL) $(LIBS)
2911-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2927+
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS) compile_rust
29122928
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29132929
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29142930

@@ -2918,11 +2934,11 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29182934
ln -s $< $@ 2>/dev/null || \
29192935
cp $< $@
29202936

2921-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2937+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS) compile_rust
29222938
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29232939
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29242940

2925-
scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
2941+
scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS) compile_rust
29262942
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
29272943
$(filter %.o,$^) $(LIBS)
29282944

@@ -3309,7 +3325,7 @@ perf: all
33093325

33103326
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
33113327

3312-
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
3328+
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) compile_rust
33133329
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
33143330

33153331
check-sha1:: t/helper/test-tool$X
@@ -3929,13 +3945,13 @@ FUZZ_CXXFLAGS ?= $(ALL_CFLAGS)
39293945
.PHONY: fuzz-all
39303946
fuzz-all: $(FUZZ_PROGRAMS)
39313947

3932-
$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
3948+
$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS compile_rust
39333949
$(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
39343950
-Wl,--allow-multiple-definition \
39353951
$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
39363952

39373953
$(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_OBJS) \
3938-
$(GITLIBS) GIT-LDFLAGS
3954+
$(GITLIBS) GIT-LDFLAGS compile_rust
39393955
$(call mkdir_p_parent_template)
39403956
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
39413957
$(filter %.o,$^) $(filter %.a,$^) $(LIBS)
@@ -3954,7 +3970,7 @@ $(UNIT_TEST_DIR)/clar.suite: $(UNIT_TEST_DIR)/clar-decls.h $(UNIT_TEST_DIR)/gene
39543970
$(UNIT_TEST_DIR)/clar/clar.o: $(UNIT_TEST_DIR)/clar.suite
39553971
$(CLAR_TEST_OBJS): $(UNIT_TEST_DIR)/clar-decls.h
39563972
$(CLAR_TEST_OBJS): EXTRA_CPPFLAGS = -I$(UNIT_TEST_DIR)
3957-
$(CLAR_TEST_PROG): $(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS) $(GITLIBS) GIT-LDFLAGS
3973+
$(CLAR_TEST_PROG): $(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS) $(GITLIBS) GIT-LDFLAGS compile_rust
39583974
$(call mkdir_p_parent_template)
39593975
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
39603976

build_rust.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
if [ -z "$CARGO_HOME" ]; then
4+
export CARGO_HOME=$HOME/.cargo
5+
echo >&2 "::warning:: CARGO_HOME is not set"
6+
fi
7+
echo "CARGO_HOME=$CARGO_HOME"
8+
9+
rustc -vV
10+
cargo --version
11+
12+
dir_git_root=${0%/*}
13+
dir_build=$1
14+
rust_target=$2
15+
crate=$3
16+
17+
dir_rust=$dir_git_root/rust
18+
19+
if [ "$dir_git_root" = "" ]; then
20+
echo "did not specify the directory for the root of git"
21+
exit 1
22+
fi
23+
24+
if [ "$dir_build" = "" ]; then
25+
echo "did not specify the build directory"
26+
exit 1
27+
fi
28+
29+
if [ "$rust_target" = "" ]; then
30+
echo "did not specify the rust_target"
31+
exit 1
32+
fi
33+
34+
if [ "$rust_target" = "release" ]; then
35+
rust_args="--release"
36+
export RUSTFLAGS='-Aunused_imports -Adead_code'
37+
elif [ "$rust_target" = "debug" ]; then
38+
rust_args=""
39+
export RUSTFLAGS='-Aunused_imports -Adead_code -C debuginfo=2 -C opt-level=1 -C force-frame-pointers=yes'
40+
else
41+
echo "illegal rust_target value $rust_target"
42+
exit 1
43+
fi
44+
45+
cd $dir_rust && cargo clean && pwd && cargo build -p $crate $rust_args; cd ..
46+
47+
libfile="lib${crate}.a"
48+
dst=$dir_build/$libfile
49+
50+
if [ "$dir_git_root" != "$dir_build" ]; then
51+
src=$dir_rust/target/$rust_target/$libfile
52+
if [ ! -f $src ]; then
53+
echo >&2 "::error:: cannot find path of static library"
54+
exit 5
55+
fi
56+
57+
rm $dst 2>/dev/null
58+
mv $src $dst
59+
fi

ci/install-dependencies.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ fi
2424

2525
case "$distro" in
2626
alpine-*)
27-
apk add --update shadow sudo meson ninja-build gcc libc-dev curl-dev openssl-dev expat-dev gettext \
27+
apk add --update shadow sudo meson ninja-build gcc libc-dev curl curl-dev openssl-dev expat-dev gettext \
2828
zlib-ng-dev pcre2-dev python3 musl-libintl perl-utils ncurses \
2929
apache2 apache2-http2 apache2-proxy apache2-ssl apache2-webdav apr-util-dbd_sqlite3 \
3030
bash cvs gnupg perl-cgi perl-dbd-sqlite perl-io-tty >/dev/null
3131
;;
3232
fedora-*|almalinux-*)
3333
dnf -yq update >/dev/null &&
34-
dnf -yq install shadow-utils sudo make gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl-devel pcre2-devel >/dev/null
34+
dnf -yq install shadow-utils sudo make gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl curl-devel pcre2-devel >/dev/null
3535
;;
3636
ubuntu-*|i386/ubuntu-*|debian-*)
3737
# Required so that apt doesn't wait for user input on certain packages.
@@ -55,8 +55,8 @@ ubuntu-*|i386/ubuntu-*|debian-*)
5555
sudo apt-get -q update
5656
sudo apt-get -q -y install \
5757
$LANGUAGES apache2 cvs cvsps git gnupg $SVN \
58-
make libssl-dev libcurl4-openssl-dev libexpat-dev wget sudo default-jre \
59-
tcl tk gettext zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl \
58+
make libssl-dev curl libcurl4-openssl-dev libexpat-dev wget sudo default-jre \
59+
tcl tk gettext zlib1g zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl \
6060
libemail-valid-perl libio-pty-perl libio-socket-ssl-perl libnet-smtp-ssl-perl libdbd-sqlite3-perl libcgi-pm-perl \
6161
libsecret-1-dev libpcre2-dev meson ninja-build pkg-config \
6262
${CC_PACKAGE:-${CC:-gcc}} $PYTHON_PACKAGE
@@ -121,13 +121,13 @@ ClangFormat)
121121
;;
122122
StaticAnalysis)
123123
sudo apt-get -q update
124-
sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
124+
sudo apt-get -q -y install coccinelle curl libcurl4-openssl-dev libssl-dev \
125125
libexpat-dev gettext make
126126
;;
127127
sparse)
128128
sudo apt-get -q update -q
129-
sudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \
130-
libexpat-dev gettext zlib1g-dev sparse
129+
sudo apt-get -q -y install libssl-dev curl libcurl4-openssl-dev \
130+
libexpat-dev gettext zlib1g zlib1g-dev sparse
131131
;;
132132
Documentation)
133133
sudo apt-get -q update

ci/install-rust.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
if [ "$(id -u)" -eq 0 ]; then
4+
echo >&2 "::warning:: installing rust as root"
5+
fi
6+
7+
if [ "$CARGO_HOME" = "" ]; then
8+
echo >&2 "::warning:: CARGO_HOME is not set"
9+
export CARGO_HOME=$HOME/.cargo
10+
fi
11+
12+
export RUSTUP_HOME=$CARGO_HOME
13+
14+
if [ "$RUST_VERSION" = "" ]; then
15+
echo >&2 "::error:: RUST_VERSION is not set"
16+
exit 2
17+
fi
18+
19+
## install rustup
20+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y
21+
if [ ! -f $CARGO_HOME/env ]; then
22+
echo "PATH=$CARGO_HOME/bin:\$PATH" > $CARGO_HOME/env
23+
fi
24+
## install a specific version of rust
25+
if [ "$BITNESS" = "32" ]; then
26+
$CARGO_HOME/bin/rustup set default-host i686-unknown-linux-gnu || exit $?
27+
$CARGO_HOME/bin/rustup install $RUST_VERSION || exit $?
28+
$CARGO_HOME/bin/rustup default --force-non-host $RUST_VERSION || exit $?
29+
else
30+
$CARGO_HOME/bin/rustup default $RUST_VERSION || exit $?
31+
fi
32+
33+
. $CARGO_HOME/env

ci/lib.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Library of functions shared by all CI scripts
22

3+
4+
export BITNESS="64"
5+
if command -v getconf >/dev/null && [ "$(getconf LONG_BIT 2>/dev/null)" = "32" ]; then
6+
export BITNESS="32"
7+
fi
8+
echo "BITNESS=$BITNESS"
9+
10+
311
if test true = "$GITHUB_ACTIONS"
412
then
513
begin_group () {

ci/make-test-artifacts.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ mkdir -p "$1" # in case ci/lib.sh decides to quit early
77

88
. ${0%/*}/lib.sh
99

10+
## install rust per user rather than system wide
11+
. ${0%/*}/install-rust.sh
12+
1013
group Build make artifacts-tar ARTIFACTS_DIRECTORY="$1"
1114

15+
if [ -d "$CARGO_HOME" ]; then
16+
rm -rf $CARGO_HOME
17+
fi
18+
1219
check_unignored_build_artifacts

ci/run-build-and-tests.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
. ${0%/*}/lib.sh
77

8+
## install rust per user rather than system wide
9+
. ${0%/*}/install-rust.sh
10+
11+
rustc -vV
12+
cargo --version || exit $?
13+
814
run_tests=t
915

1016
case "$jobname" in
@@ -72,5 +78,9 @@ case "$jobname" in
7278
;;
7379
esac
7480

81+
if [ -d "$CARGO_HOME" ]; then
82+
rm -rf $CARGO_HOME
83+
fi
84+
7585
check_unignored_build_artifacts
7686
save_good_tree

meson.build

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,17 @@ else
277277
rustflags = '-Aunused_imports -Adead_code -C debuginfo=2 -C opt-level=1 -C force-frame-pointers=yes'
278278
endif
279279

280-
281-
rust_leaf = custom_target('rust_leaf',
280+
rust_build_xdiff = custom_target('rust_build_xdiff',
282281
output: 'libxdiff.a',
283282
build_by_default: true,
284283
build_always_stale: true,
285-
command: ['cargo', 'build',
286-
'--manifest-path', meson.project_source_root() / 'rust/Cargo.toml'
287-
] + rust_args,
288-
env: {
289-
'RUSTFLAGS': rustflags,
290-
},
284+
command: [
285+
meson.project_source_root() / 'build_rust.sh',
286+
meson.current_build_dir(), rust_target, 'xdiff',
287+
],
291288
install: false,
292289
)
293290

294-
rust_xdiff_dep = declare_dependency(
295-
link_args: ['-L' + meson.project_source_root() / 'rust/target' / rust_target, '-lxdiff'],
296-
# include_directories: include_directories('xdiff/include'), # Adjust if you expose headers
297-
)
298-
299-
300291
compiler = meson.get_compiler('c')
301292

302293
libgit_sources = [
@@ -1707,17 +1698,18 @@ version_def_h = custom_target(
17071698
)
17081699
libgit_sources += version_def_h
17091700

1710-
libgit_dependencies += rust_xdiff_dep
1711-
17121701
libgit = declare_dependency(
1713-
link_with: static_library('git',
1714-
sources: libgit_sources,
1715-
c_args: libgit_c_args + [
1716-
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1717-
],
1718-
dependencies: libgit_dependencies,
1719-
include_directories: libgit_include_directories,
1720-
),
1702+
link_with: [
1703+
static_library('git',
1704+
sources: libgit_sources,
1705+
c_args: libgit_c_args + [
1706+
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
1707+
],
1708+
dependencies: libgit_dependencies,
1709+
include_directories: libgit_include_directories,
1710+
),
1711+
rust_build_xdiff,
1712+
],
17211713
compile_args: libgit_c_args,
17221714
dependencies: libgit_dependencies,
17231715
include_directories: libgit_include_directories,

0 commit comments

Comments
 (0)