oasislinux / oasis

a small statically-linked linux system
Other
2.75k stars 84 forks source link

ninja commit fails; out/pkg/awk/maketab: not found #59

Closed ghost closed 1 year ago

ghost commented 1 year ago

I've been having some trouble building oasis from the instructions. I did a successful build a few weeks ago but now it is failing and I can't figure out why. I've been over the instructions a dozen times and it always fails in the same way

The only changes I've made to config.lua are the exact same changes suggested on the Wiki.

ninja -v commit fails with the following error:

[1/6111] out/pkg/awk/maketab out/pkg/awk/awkgram.tab.h >out/pkg/awk/proctab.c
FAILED: out/pkg/awk/proctab.c 
out/pkg/awk/maketab out/pkg/awk/awkgram.tab.h >out/pkg/awk/proctab.c
/bin/sh: 1: out/pkg/awk/maketab: not found
[2/6111] x86_64-linux-musl-cc -MD -MF out/pkg/bc/bc/main.c.o.d -Os -fPIE -pipe -std=c99 -Wall -Wpedantic -D _POSIX_C_SOURCE=200809L -I ./pkg/bc -I ./pkg/bc/src/h -c -o out/pkg/bc/bc/main.c.o pkg/bc/src/bc/main.c
[3/6111] x86_64-linux-musl-cc -MD -MF out/pkg/bc/bc/load.c.o.d -Os -fPIE -pipe -std=c99 -Wall -Wpedantic -D _POSIX_C_SOURCE=200809L -I ./pkg/bc -I ./pkg/bc/src/h -c -o out/pkg/bc/bc/load.c.o pkg/bc/src/bc/load.c
[4/6111] x86_64-linux-musl-cc -MD -MF out/pkg/bc/bc/execute.c.o.d -Os -fPIE -pipe -std=c99 -Wall -Wpedantic -D _POSIX_C_SOURCE=200809L -I ./pkg/bc -I ./pkg/bc/src/h -c -o out/pkg/bc/bc/execute.c.o pkg/bc/src/bc/execute.c
[5/6111] x86_64-linux-musl-cc -MD -MF out/pkg/bc/bc/scan.c.o.d -Os -fPIE -pipe -std=c99 -Wall -Wpedantic -D _POSIX_C_SOURCE=200809L -I ./pkg/bc -I ./pkg/bc/src/h -c -o out/pkg/bc/bc/scan.c.o pkg/bc/src/bc/scan.c
[6/6111] x86_64-linux-musl-cc -MD -MF out/pkg/bc/bc/bc.c.o.d -Os -fPIE -pipe -std=c99 -Wall -Wpedantic -D _POSIX_C_SOURCE=200809L -I ./pkg/bc -I ./pkg/bc/src/h -c -o out/pkg/bc/bc/bc.c.o pkg/bc/src/bc/bc.c
ninja: build stopped: subcommand failed.

Yet out/pkg/awk/maketab does indeed exist

Another issue I've been running into is that x86_64-linux-musl-{cross|native}/bin does not contain a cc binary so I always have to symlink bin/x86_64-linux-musl-cc to bin/cc. If I don't do this, I will get an error on ninja commit saying /bin/sh: 1: cc: not found. Same result with both the cross and native packages.

michaelforney commented 1 year ago

Your two issues are related.

The maketab issue is because you configured it to build binaries for the host system (I suspect on a glibc system) with a musl cross-compiler. The not found error is referring to the interpreter of the executable not being found (i.e. /lib/ld-musl-x86_64.so.1), not the executable itself. It's basically the same issue as if you were to try to run a script with a shebang line of #!/nonexistent/path.

oasis supports cross-compilation, which means that if we need to build and run any tools during the build process (for example, to generate sources), they need to be built with a compiler that targets the running system, not the target system. This is the difference between the target and host sections in config.lua. The build system expects that a compiler for the running system is available at cc, which is usually the case. By symlinking it to x86_64-linux-musl-cc, you are doing the same thing as setting host.cc in config.lua, which tells oasis to use x86_64-linux-musl-cc as the compiler to build binaries for the running system.

The solution is to install a C compiler for the host system and delete the cc symlink you created. How to do this depends on the host system. For Debian-based systems, installing the build-essential package is sufficient.

Another option if you don't want to (or can't) install packages on the host system is to use the musl cross-compiler, but tell it to build host binaries statically. This works if the architecture of the host system matches the target system, since static binaries have no dependencies like an interpreter. You can do this by setting host.platform='x86_64-linux-musl' in config.lua (just like the target section), and adding -static to host.cflags.

ghost commented 1 year ago

Thank you so much for the detailed reply. I finally managed to get past the error. It was a tricky error to understand and debug, and I couldn't find any recent changes to the oasis repo that could have caused it. Installing build-essential ultimately did the trick. I had previously tried to install the musl and musl-tools packages, which did create cc on the system but I was getting gcc lib errors, which confused me. I never bothered to try modifying the host.platform (host machine==target), which I now suspect was the step I was missing. So I think I was at least halfway there.

I greatly appreciate the help