Skip to content

Commit 719d513

Browse files
committed
profiling: update build script to cross compiling 32 bit on 64 bit linux
1 parent 1a7e673 commit 719d513

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

build-profiling-ffi.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ ARG_FEATURES=""
1919
run_tests=true
2020

2121
usage() {
22-
echo "Usage: `basename "$0"` [-h] [-f FEATURES] [-T] dest-dir"
22+
echo "Usage: `basename "$0"` [-h] [-f FEATURES] [-t TRIPLET] [-T] dest-dir"
2323
echo
2424
echo "Options:"
2525
echo " -h This help text"
2626
echo " -f FEATURES Enable specified features (comma separated if more than one)"
27+
echo " -t TRIPLET Target triplet to build for, defaults to host triplet"
2728
echo " -T Skip checks after building"
2829
exit $1
2930
}
3031

31-
while getopts f:hT flag
32+
while getopts f:ht:T flag
3233
do
3334
case "${flag}" in
3435
f)
@@ -39,6 +40,11 @@ do
3940
h)
4041
usage 0
4142
;;
43+
t)
44+
target=${OPTARG}
45+
shift
46+
shift
47+
;;
4248
T)
4349
run_tests=false
4450
shift
@@ -59,7 +65,9 @@ fi
5965
mkdir -v -p "$destdir/include/datadog" "$destdir/lib/pkgconfig" "$destdir/cmake"
6066

6167
version=$(awk -F\" '$1 ~ /^version/ { print $2 }' < profiling-ffi/Cargo.toml)
62-
target="$(rustc -vV | awk '/^host:/ { print $2 }')"
68+
if [ -z ${target+x} ]; then
69+
target="$(rustc -vV | awk '/^host:/ { print $2 }')"
70+
fi
6371
shared_library_suffix=".so"
6472
static_library_suffix=".a"
6573
library_prefix="lib"
@@ -77,7 +85,7 @@ symbolizer=0
7785
# provided. At least on Alpine, libgcc_s may not even exist in the users'
7886
# images, so -static-libgcc is recommended there.
7987
case "$target" in
80-
"x86_64-alpine-linux-musl"|"aarch64-alpine-linux-musl")
88+
"x86_64-alpine-linux-musl"|"aarch64-alpine-linux-musl"|"i686-alpine-linux-musl")
8189
expected_native_static_libs=" -lssp_nonshared -lgcc_s -lc"
8290
native_static_libs=" -lssp_nonshared -lc"
8391
# on alpine musl, Rust adds some weird runpath to cdylibs
@@ -94,7 +102,7 @@ case "$target" in
94102
fix_macos_rpath=1
95103
;;
96104

97-
"x86_64-unknown-linux-gnu"|"aarch64-unknown-linux-gnu")
105+
"x86_64-unknown-linux-gnu"|"aarch64-unknown-linux-gnu"|"i686-unknown-linux-gnu")
98106
expected_native_static_libs=" -ldl -lrt -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -ldl -lutil"
99107
native_static_libs=" -ldl -lrt -lpthread -lc -lm -lrt -lpthread -lutil -ldl -lutil"
100108
symbolizer=1
@@ -246,7 +254,7 @@ if [[ "$symbolizer" -eq 1 ]]; then
246254
# Copy the blazesym header separately because The blazesym header isn't auto-generated by cbindgen
247255
# so we don't need to remove definitions that are already present in `common.h` using dedup_headers
248256
cp "$CARGO_TARGET_DIR/include/datadog/blazesym.h" "$destdir/include/datadog/blazesym.h"
249-
fi
257+
fi
250258

251259

252260
# Don't build the crashtracker on windows
@@ -260,7 +268,13 @@ if [[ "$target" != "x86_64-pc-windows-msvc" ]]; then
260268
[ -d $CRASHTRACKER_BUILD_DIR ] && rm -r $CRASHTRACKER_BUILD_DIR
261269
mkdir -p $CRASHTRACKER_BUILD_DIR
262270
cd $CRASHTRACKER_BUILD_DIR
263-
cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
271+
272+
if [[ "$target" =~ ^i686 ]]; then
273+
CFLAGS=-m32 CXXFLAGS=-m32 cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
274+
else
275+
cmake -S $CRASHTRACKER_SRC_DIR -DDatadog_ROOT=$ABS_DESTDIR
276+
fi
277+
264278
cmake --build .
265279
mkdir -p $ABS_DESTDIR/bin
266280
cp libdatadog-crashtracking-receiver $ABS_DESTDIR/bin

ddcommon/src/rate_limiter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn now() -> u64 {
5454
tv_nsec: 0,
5555
};
5656
unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts) };
57-
(ts.tv_sec * TIME_PER_SECOND + ts.tv_nsec) as u64
57+
(ts.tv_sec as i64 * TIME_PER_SECOND + ts.tv_nsec as i64) as u64
5858
};
5959
now
6060
}

0 commit comments

Comments
 (0)