rust: Define `getloadavg()`

Due to libgit2-sys crate.

Co-authored-by: Tee KOBAYASHI <xtkoba@gmail.com>
This commit is contained in:
PeroSar 2022-05-20 03:14:11 +00:00 committed by Henrik Grimler
parent 19fe5b3a48
commit 5de8271907
No known key found for this signature in database
GPG Key ID: B0076E490B71616B
2 changed files with 60 additions and 2 deletions

View File

@ -36,6 +36,8 @@ termux_step_configure() {
local env_host=$(printf $CARGO_TARGET_NAME | tr a-z A-Z | sed s/-/_/g)
export ${env_host}_OPENSSL_DIR=$TERMUX_PREFIX
export CARGO_TARGET_${env_host}_RUSTFLAGS="-C link-arg=-l:libgetloadavg.a"
export X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu
export X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR=/usr/include
export PKG_CONFIG_ALLOW_CROSS=1
@ -43,7 +45,6 @@ termux_step_configure() {
export CC_x86_64_unknown_linux_gnu=gcc
export CFLAGS_x86_64_unknown_linux_gnu="-O2"
export LLVM_MAJOR_VERSION=$(. $TERMUX_SCRIPTDIR/packages/libllvm/build.sh; echo $LLVM_MAJOR_VERSION)
unset CC CXX CPP LD CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PKG_CONFIG RANLIB
# we can't use -L$PREFIX/lib since it breaks things but we need to link against libLLVM-9.so
ln -sf $PREFIX/lib/libLLVM-$LLVM_MAJOR_VERSION.so $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/
@ -60,9 +61,16 @@ termux_step_configure() {
}
termux_step_make() {
return 0;
# ld: error: undefined symbol: getloadavg
# >>> referenced by rand.c
$CC $CPPFLAGS -c "$TERMUX_PKG_BUILDER_DIR"/getloadavg.c
$AR rcu $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/libgetloadavg.a \
getloadavg.o
}
termux_step_make_install() {
unset CC CXX CPP LD CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PKG_CONFIG RANLIB
if [ $TERMUX_ARCH = "x86_64" ]; then
mv $TERMUX_PREFIX ${TERMUX_PREFIX}a
$TERMUX_PKG_SRCDIR/x.py build --host x86_64-unknown-linux-gnu --stage 1 cargo || $TERMUX_PKG_SRCDIR/x.py build --host x86_64-unknown-linux-gnu --stage 1 rls || $TERMUX_PKG_SRCDIR/x.py build --host x86_64-unknown-linux-gnu --stage 1 rustfmt || $TERMUX_PKG_SRCDIR/x.py --stage 1 --host x86_64-unknown-linux-gnu build rustdoc || $TERMUX_PKG_SRCDIR/x.py --stage 1 --host x86_64-unknown-linux-gnu build error_index_generator || true
@ -92,8 +100,10 @@ termux_step_make_install() {
rust-installer-version \
manifest-* \
x86_64-unknown-linux-gnu
rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/libLLVM-$LLVM_MAJOR_VERSION.so
rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/libc++_shared.a
rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/$TERMUX_HOST_PLATFORM/$TERMUX_PKG_API_LEVEL/libgetloadavg.a
}
termux_step_post_massage() {

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2018 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined __ANDROID__ && __ANDROID_API__ < 29
#include <stdlib.h>
#include <sys/sysinfo.h>
int getloadavg(double averages[], int n) {
if (n < 0) return -1;
if (n > 3) n = 3;
struct sysinfo si;
if (sysinfo(&si) == -1) return -1;
for (int i = 0; i < n; ++i) {
averages[i] = (double)(si.loads[i]) / (double)(1 << SI_LOAD_SHIFT);
}
return n;
}
#endif