mirror of https://gitlab.com/nakst/essence
using the pre-built cross compiler
This commit is contained in:
parent
a3aaf6e85d
commit
473e2de505
41
util/build.c
41
util/build.c
|
@ -215,6 +215,8 @@ void OutputStartOfBuildINI(FILE *f, bool forceDebugBuildOff) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildUtilities();
|
void BuildUtilities();
|
||||||
|
void DoCommand(const char *l);
|
||||||
|
void SaveConfig();
|
||||||
|
|
||||||
#define COMPILE_SKIP_COMPILE (1 << 1)
|
#define COMPILE_SKIP_COMPILE (1 << 1)
|
||||||
#define COMPILE_DO_BUILD (1 << 2)
|
#define COMPILE_DO_BUILD (1 << 2)
|
||||||
|
@ -364,7 +366,6 @@ void BuildUtilities() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BUILD_UTILITY("render_svg", "-lm", "");
|
BUILD_UTILITY("render_svg", "-lm", "");
|
||||||
BUILD_UTILITY("change_sysroot", "", "");
|
|
||||||
BUILD_UTILITY("build_core", "-pthread -DPARALLEL_BUILD", "");
|
BUILD_UTILITY("build_core", "-pthread -DPARALLEL_BUILD", "");
|
||||||
|
|
||||||
if (canBuildLuigi) {
|
if (canBuildLuigi) {
|
||||||
|
@ -562,12 +563,44 @@ void Run(int emulator, int log, int debug) {
|
||||||
void BuildCrossCompiler() {
|
void BuildCrossCompiler() {
|
||||||
if (!CallSystem("whoami | grep root")) {
|
if (!CallSystem("whoami | grep root")) {
|
||||||
printf("Error: Build should not be run as root.\n");
|
printf("Error: Build should not be run as root.\n");
|
||||||
return;
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool usePreBuilt;
|
||||||
|
|
||||||
{
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("A cross compiler for Essence needs to be built.\n");
|
printf("To build Essence, you need a cross compiler.\n");
|
||||||
|
#ifdef __linux__
|
||||||
|
printf("You can either use a pre-built cross compiler (~40MB download), or build one locally.\n");
|
||||||
|
printf("Type 'yes' if you want to use the pre-built cross compiler.\n");
|
||||||
|
usePreBuilt = GetYes();
|
||||||
|
#else
|
||||||
|
printf("A cross compiler will be built for you automatically.\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usePreBuilt) {
|
||||||
|
DoCommand("get-source prefix https://github.com/nakst/build-gcc-x86_64-essence/releases/download/gcc-v11.1.0/out.tar.xz");
|
||||||
|
if (CallSystem("mv bin/source cross")) goto fail;
|
||||||
|
if (CallSystem("mkdir -p cross/bin2")) goto fail;
|
||||||
|
foundValidCrossCompiler = true;
|
||||||
|
getcwd(compilerPath, sizeof(compilerPath));
|
||||||
|
strcat(compilerPath, "/cross/bin2");
|
||||||
|
if (CallSystem("gcc -o bin/change_sysroot util/change_sysroot.c -Wall -Wextra")) goto fail;
|
||||||
|
#define MAKE_TOOLCHAIN_WRAPPER(tool) \
|
||||||
|
if (CallSystem("gcc -o cross/bin2/" TOOLCHAIN_PREFIX "-" tool " util/toolchain_wrapper.c -Wall -Wextra -g -DTOOL=" TOOLCHAIN_PREFIX "-" tool)) goto fail;
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("ar");
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("gcc");
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("g++");
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("ld");
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("nm");
|
||||||
|
MAKE_TOOLCHAIN_WRAPPER("strip");
|
||||||
|
SaveConfig();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
printf("- You need to be connected to the internet. ~100MB will be downloaded.\n");
|
printf("- You need to be connected to the internet. ~100MB will be downloaded.\n");
|
||||||
printf("- You need ~3GB of drive space available.\n");
|
printf("- You need ~3GB of drive space available.\n");
|
||||||
printf("- You need ~8GB of RAM available.\n");
|
printf("- You need ~8GB of RAM available.\n");
|
||||||
|
@ -1531,7 +1564,7 @@ void DoCommand(const char *l) {
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else if (CallSystemF("curl %s > %s", url, name)) {
|
} else if (CallSystemF("curl -L %s > %s", url, name)) {
|
||||||
CallSystemF("rm %s", name); // Remove partially downloaded file.
|
CallSystemF("rm %s", name); // Remove partially downloaded file.
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,7 @@ int main(int argc, char **argv) {
|
||||||
ptrace(PTRACE_GETREGS, pid, 0, ®isters);
|
ptrace(PTRACE_GETREGS, pid, 0, ®isters);
|
||||||
|
|
||||||
if (registers.orig_rax == SYS_access
|
if (registers.orig_rax == SYS_access
|
||||||
|
|| registers.orig_rax == SYS_chown
|
||||||
|| registers.orig_rax == SYS_lstat
|
|| registers.orig_rax == SYS_lstat
|
||||||
|| registers.orig_rax == SYS_readlink
|
|| registers.orig_rax == SYS_readlink
|
||||||
|| registers.orig_rax == SYS_stat
|
|| registers.orig_rax == SYS_stat
|
||||||
|
@ -129,17 +130,21 @@ int main(int argc, char **argv) {
|
||||||
|| registers.orig_rax == SYS_fcntl
|
|| registers.orig_rax == SYS_fcntl
|
||||||
|| registers.orig_rax == SYS_fstat
|
|| registers.orig_rax == SYS_fstat
|
||||||
|| registers.orig_rax == SYS_getcwd
|
|| registers.orig_rax == SYS_getcwd
|
||||||
|
|| registers.orig_rax == SYS_getdents64
|
||||||
|| registers.orig_rax == SYS_getrandom
|
|| registers.orig_rax == SYS_getrandom
|
||||||
|| registers.orig_rax == SYS_getrusage
|
|| registers.orig_rax == SYS_getrusage
|
||||||
|| registers.orig_rax == SYS_ioctl
|
|| registers.orig_rax == SYS_ioctl
|
||||||
|| registers.orig_rax == SYS_lseek
|
|| registers.orig_rax == SYS_lseek
|
||||||
|
|| registers.orig_rax == SYS_madvise
|
||||||
|| registers.orig_rax == SYS_mmap
|
|| registers.orig_rax == SYS_mmap
|
||||||
|| registers.orig_rax == SYS_mprotect
|
|| registers.orig_rax == SYS_mprotect
|
||||||
|
|| registers.orig_rax == SYS_mremap
|
||||||
|| registers.orig_rax == SYS_munmap
|
|| registers.orig_rax == SYS_munmap
|
||||||
|| registers.orig_rax == SYS_pipe2
|
|| registers.orig_rax == SYS_pipe2
|
||||||
|| registers.orig_rax == SYS_pread64
|
|| registers.orig_rax == SYS_pread64
|
||||||
|| registers.orig_rax == SYS_prlimit64
|
|| registers.orig_rax == SYS_prlimit64
|
||||||
|| registers.orig_rax == SYS_read
|
|| registers.orig_rax == SYS_read
|
||||||
|
|| registers.orig_rax == SYS_rename
|
||||||
|| registers.orig_rax == SYS_rt_sigaction
|
|| registers.orig_rax == SYS_rt_sigaction
|
||||||
|| registers.orig_rax == SYS_rt_sigprocmask
|
|| registers.orig_rax == SYS_rt_sigprocmask
|
||||||
|| registers.orig_rax == SYS_set_robust_list
|
|| registers.orig_rax == SYS_set_robust_list
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#define _STRING(x) #x
|
||||||
|
#define STRING(x) _STRING(x)
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
char buffer[PATH_MAX] = {}, change[PATH_MAX] = {}, sysroot[PATH_MAX] = {}, tool[PATH_MAX] = {};
|
||||||
|
readlink("/proc/self/exe", buffer, sizeof(buffer));
|
||||||
|
int directoryPosition = 0;
|
||||||
|
for (int i = 0; buffer[i]; i++) if (buffer[i] == '/') directoryPosition = i;
|
||||||
|
buffer[directoryPosition] = 0;
|
||||||
|
for (int i = 0; buffer[i]; i++) if (buffer[i] == '/') directoryPosition = i;
|
||||||
|
buffer[directoryPosition] = 0;
|
||||||
|
for (int i = 0; buffer[i]; i++) if (buffer[i] == '/') directoryPosition = i;
|
||||||
|
buffer[directoryPosition] = 0;
|
||||||
|
strcpy(change, buffer);
|
||||||
|
strcpy(sysroot, buffer);
|
||||||
|
strcpy(tool, buffer);
|
||||||
|
strcat(change, "/bin/change_sysroot");
|
||||||
|
strcat(sysroot, "/root/");
|
||||||
|
strcat(tool, "/cross/bin/" STRING(TOOL));
|
||||||
|
// printf("'%s'\n", change);
|
||||||
|
// printf("'%s'\n", sysroot);
|
||||||
|
// printf("'%s'\n", tool);
|
||||||
|
char **newArgv = (char **) calloc(sizeof(char *), (argc + 4));
|
||||||
|
newArgv[0] = change;
|
||||||
|
newArgv[1] = "/home/runner/work/build-gcc-x86_64-essence/build-gcc-x86_64-essence/essence/root/";
|
||||||
|
newArgv[2] = sysroot;
|
||||||
|
newArgv[3] = tool;
|
||||||
|
memcpy(newArgv + 4, argv + 1, (argc - 1) * sizeof(char *));
|
||||||
|
execv(newArgv[0], newArgv);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue