cross/crossdirect: use ccache, execve, -Werror (!299)

Instead of running compilers directly, let them go through the native
ccache binary. Note that it will still use the foreign arches cache dir
because the native cache dir would be at /native/home/pmos/.ccache.

Use execve instead of setenv and execv, because that didn't work with
LD_LIBRARY_PATH (ccache was complaining that it couldn't load zlib).

Enable -Werror, because we are maintaining this program and it helps
us catching bugs early.
This commit is contained in:
Oliver Smith 2019-04-03 20:45:16 +02:00
parent 9c90da7969
commit 958f597a6c
2 changed files with 20 additions and 8 deletions

View file

@ -13,7 +13,7 @@
# implementation details (llvm, fakeroot, rpath).
pkgname=crossdirect
pkgver=1
pkgver=2
pkgrel=0
pkgdesc="Wrappers to launch native cross compilers in foreign chroots"
url="https://postmarketOS.org"
@ -29,7 +29,13 @@ build() {
for _arch in $_archs; do
[ "$_arch" == "$CARCH" ] && continue
_hostspec="$(arch_to_hostspec $_arch)"
$CC -o "crossdirect-$_arch" -static -DHOSTSPEC="\"$_hostspec\"" \
# Build with -Werror, because we maintain this short program. (If
# upstream is elsewhere, having -Werror is usually not desired.)
$CC -o "crossdirect-$_arch" \
-static \
-Werror \
-DHOSTSPEC="\"$_hostspec\"" \
crossdirect.c
done
}
@ -57,4 +63,4 @@ package() {
done
done
}
sha512sums="12801031928103bd898a0d54a5c68b33da9bded10a3d145fdf5ce8b70eb0bbbcdd50764279004b6997d85d710fa581dc8b05aa5e0eb62d50c1054cc6d66db87f crossdirect.c"
sha512sums="6a94a2e0842c95b8ca862b71a7b54f280d0fe9da40fe40691628ef6089a995159c1b53513fb006589af064110a9d2592b24c772264c02d27e7bac9871428f757 crossdirect.c"

View file

@ -9,6 +9,8 @@
#include <limits.h>
#include <unistd.h>
#define NATIVE_BIN_DIR "/native/usr/lib/ccache/bin"
void exit_userfriendly() {
fprintf(stderr, "Please report this at: https://gitlab.com/postmarketOS/pmaports/issues\n");
fprintf(stderr, "As a workaround, you can compile without crossdirect.\n");
@ -25,9 +27,9 @@ int main(int argc, char** argv) {
bool startsWithHostSpec = (strncmp(HOSTSPEC, executableName, sizeof(HOSTSPEC) -1) == 0);
if (isClang || startsWithHostSpec) {
snprintf(newExecutable, sizeof(newExecutable), "/native/usr/bin/%s", executableName);
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/%s", executableName);
} else {
snprintf(newExecutable, sizeof(newExecutable), "/native/usr/bin/" HOSTSPEC "-%s", executableName);
snprintf(newExecutable, sizeof(newExecutable), NATIVE_BIN_DIR "/" HOSTSPEC "-%s", executableName);
}
char** newArgsPtr = newargv;
@ -58,19 +60,23 @@ int main(int argc, char** argv) {
*newArgsPtr = NULL;
// new arguments prepared; now setup environmental vars
setenv("LD_LIBRARY_PATH", "/native/lib:/native/usr/lib", true);
char* env[] = {"LD_PRELOAD=",
"LD_LIBRARY_PATH=/native/lib:/native/usr/lib",
"CCACHE_PATH=/native/usr/bin",
NULL};
char* ldPreload = getenv("LD_PRELOAD");
if (ldPreload) {
if (strcmp(ldPreload, "/usr/lib/libfakeroot.so") == 0) {
setenv("LD_PRELOAD", "/native/usr/lib/libfakeroot.so", true);
env[0] = "LD_PRELOAD=/native/usr/lib/libfakeroot.so";
} else {
fprintf(stderr, "ERROR: crossdirect: can't handle LD_PRELOAD: %s\n", ldPreload);
exit_userfriendly();
}
}
if (execv(newExecutable, newargv) == -1) {
if (execve(newExecutable, newargv, env) == -1) {
fprintf(stderr, "ERROR: crossdirect: failed to execute %s: %s\n", newExecutable, strerror(errno));
fprintf(stderr, "Maybe the target arch is missing in the ccache-cross-symlinks package?\n");
exit_userfriendly();
}
return 1;