jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.37k stars 597 forks source link

Support for docker build on MacOs #287

Open Et7f3 opened 2 years ago

Et7f3 commented 2 years ago

Hello I build a docker image with:

docker build -t cosmopolitan .

and builded:

docker run --rm -v$PWD:/workdir cosmopolitan sh -c 'cd workdir; make MODE=ansi -j8 -O all' 2>stderr.txt

Host is MacOs. Is this way of building is excepted to be supported (maybe an older version of gcc ?). Is

I would like to help for hacktoberfest. I beggined to fix easy warning here https://github.com/jart/cosmopolitan/pull/286

Dockerfile.txt (renamed just for bypass GitHub limitation) stderr.txt

Et7f3 commented 2 years ago

Ok I installed linux-headers and progressed more. I used default MODE and done a better progress. However now I fail with:

♥cosmo
o//test/libc/release/smoke-nms.com.tmp.21: exec: line 13: /workdir/o/tmp/ape-loader: not found

`make MODE= -j8 o//test/libc/release/smoke-nms.com.runs` exited with 127:
o//test/libc/release/smoke-nms.com
consumed 5,120µs wall time
ballooned to 1,056kb in size
needed 2,524us cpu (22% kernel)
caused 126 page faults (100% memcpy)
10 context switch (100% consensual)

make: *** [build/rules.mk:78: o//test/libc/release/smoke-nms.com.runs] Error 127

Don't know how to progress more. I don't see make target.

jart commented 2 years ago

If smoke-nms.com is failing then it means that something is going wrong wrong with "ape no modify self" in your docker environment.

If you don't need the alternative nms bootloader, then it's safe to ignore this error. There are two ways you can do that. The first is you can instruct make to only build what you need, by saying something like make o//examples/hello.com. If you say make o//examples then it'll build all examples and only examples. The second choice is to just comment out the failing test rule.

Ideally I want to solve this but I'm not sure if I can reproduce your environment. Could you help us troubleshoot, possibly by editing ape/ape.S?

I've been doing a lot of work on ape-loader and integrating it into execve() this past week. That'll be pushed soon and it might help address the issue.

jart commented 2 years ago

Contributions welcome from the Hacktoberfest crowd if anyone with a Mac Docker environment wants to help us troubleshoot and learn more about this issue.

Et7f3 commented 2 years ago

if I can reproduce your environment. Could you help us troubleshoot, possibly by editing ape/ape.S?

I tried to setup GitHub Actions (they provide multiple os and are integrated) to reproduce my issue but got other issues 😬. I intended to use this repo to learn about linker script so don't think I have enough knowledge to debug.

jart commented 2 years ago

Do you think I knew anything about assembly or linker scripts when I started this project? You have the ability to do things like comment out these two lines:

https://github.com/jart/cosmopolitan/blob/903cc38c37670577f5dcff1aef4b14e26718b264/ape/ape.S#L545-L546

See if that changes things. Then rinse wash and repeat. You will eventually figure out the problem if you have the time.

Et7f3 commented 2 years ago

Ok I commented those two lines and still got:

 7,582,530⏰   852,544⏳  28,060k       0iop o/third_party/gcc/bin/x86_64-linux-musl-gcc -o o//test/libc/release/smoke-nms.com.dbg -Os -fno-code-hoisting -static -no-pie -fno-pie -nostdlib -nostdinc -Wl,-T,o//ape/ape.lds -include o/cosmopolitan.h test/libc/release/smoke.c o//libc/crt/crt.o o//ape/ape-no-modify-self.o o//cosmopolitan.a -no-canonical-prefixes -fdiagnostics-color=always -mno-red-zone -D__MNO_RED_ZONE__ -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
    38,944⏰     3,784⏳   1,060k       0iop o/third_party/gcc/bin/x86_64-linux-musl-objcopy -S -O binary o//test/libc/release/smoke-nms.com.dbg o//test/libc/release/smoke-nms.com
o//test/libc/release/smoke-nms.com.tmp.51: exec: line 12: /workdir/o/tmp/ape-loader: not found

`make MODE= -j8 o//test/libc/release/smoke-nms.com.runs` exited with 127:
o//test/libc/release/smoke-nms.com

I have pulled change of master d6a03982

I removed comment and added verbose mode:

+ command -v o//test/libc/release/smoke-nms.com.tmp.67
+ o=o//test/libc/release/smoke-nms.com.tmp.67
+ type ape-loader
+ '[' '!' -d /Applications ]
+ t=/workdir/o/tmp/ape-loader
+ '[' -x /workdir/o/tmp/ape-loader ]
+ dd 'if=o//test/libc/release/smoke-nms.com.tmp.67' 'of=/workdir/o/tmp/ape-loader.68' 'skip=    2816' 'count=      28' 'bs=64'
+ exec /workdir/o/tmp/ape-loader o//test/libc/release/smoke-nms.com.tmp.67
o//test/libc/release/smoke-nms.com.tmp.67: exec: line 14: /workdir/o/tmp/ape-loader: not found

How o//test/libc/release/smoke-nms.com.tmp.67 is supposed to be created. dd except as input but I don't find it so it might explain why he can't create the loader.

pablo-mayrgundter commented 1 year ago

I'm also on M1 and trying a containerized build. Found this issue so following along with the above.

> uname -a
Darwin MacBook-Air-5.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101 arm64

I use the same docker file from above:

FROM alpine:latest

RUN apk add git bash make clang gcc g++

and then run the dockerized build command from within my fork of cosmo repo:

cosmo> git log --oneline | head -3
adaaeb7dd (HEAD -> master, origin/master, origin/HEAD) Add itimerval to sys/time.h (#572)
164e2ab27 Rename MapContentType to ProgramContentType (#570)
d2cec808d Fix redbean to check for file read result when -F option is used (#569)
cosmo> docker run --rm -v$PWD:/workdir cosmopolitan sh -c 'cd workdir; make MODE=ansi -j8 -O all' 2>stderr.txt
cosmo> tail -10 stderr.txt
chmod: /root/.ape.9: No such file or directory
mv: can't rename '/root/.ape.9': No such file or directory
build/bootstrap/cocmd.com: exec: line 15: /root/.ape: not found
chmod: /root/.ape.16: No such file or directory
mv: can't rename '/root/.ape.16': No such file or directory
build/bootstrap/cocmd.com: exec: line 15: /root/.ape: not found
chmod: /root/.ape.23: No such file or directory
mv: can't rename '/root/.ape.23': No such file or directory

Unfamiliar with ape.. but this seems weird to be using root instead of current working dir (workdir here) or /tmp?

Et7f3 commented 1 year ago

It use current user home to extract the ape loader for security reasons. User home of root happen to be /root

yjfvictor commented 10 months ago

Here is my test. You can have a try.

docker-cosmopolitan.zip

pablo-mayrgundter commented 10 months ago

Well, docker goes well but build doesn't. Maybe smth obv tho? haven't looked at this in a while:

 => ERROR [4/6] RUN /bin/sh -c 'ape-install || cosmocc --update'
                                       1.0s
------
 > [4/6] RUN /bin/sh -c 'ape-install || cosmocc --update':
#0 0.259 Actually Portable Executable (APE) Installer
#0 0.259 Author:  Justine Tunney ***@***.***>
#0 0.259 using prebuilt ape loader from cosmo repo
#0 0.263
#0 0.263 installing o//ape/ape.elf to /usr/bin/ape
#0 0.263  mv -f o//ape/ape.elf /usr/bin/ape
#0 0.265 done
#0 0.266
#0 0.266 mounting binfmt_misc into your kernel
#0 0.266 you may need to edit configs to persist across reboot
#0 0.266 mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
#0 0.268 mount: permission denied (are you root?)
#0 0.269 building cosmo host toolchain...
#0 0.274 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.278 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.282 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.902 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.971 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.972 make: *** [build/rules.mk:48: o//libc/nexgen32e/argv.o] Error 127
#0 0.972 make: *** Waiting for unfinished jobs....
#0 0.972 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.972 make: *** [build/rules.mk:48: o//libc/nexgen32e/argc.o] Error 127
#0 0.973 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.973 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.973 make: *** [build/rules.mk:48: o//libc/nexgen32e/auxv.o] Error 127
#0 0.973 make: *** [libc/nexgen32e/nexgen32e.mk:92:
o//libc/nexgen32e/blink_linux_aarch64.o] Error 127
#0 0.975 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.975 make: *** [libc/nexgen32e/nexgen32e.mk:90:
o//libc/nexgen32e/blink_xnu_aarch64.o] Error 127
#0 0.975 build/bootstrap/cocmd.com: this ape binary lacks aarch64 support
#0 0.975 make: *** [libc/nexgen32e/nexgen32e.mk:88:
o//libc/nexgen32e/checkstackalign.o] Error 127
------
Dockerfile:6
--------------------
   4 |     RUN /bin/sh -c 'git clone https://github.com/jart/cosmopolitan
/opt/cosmo'
   5 |     ENV PATH="/opt/cosmo/bin:/opt/cosmos/bin:$PATH"
   6 | >>> RUN /bin/sh -c 'ape-install || cosmocc --update'
   7 |     RUN /bin/sh -c 'mkdir /app'
   8 |     WORKDIR /app
--------------------
ERROR: failed to solve: process "/bin/sh -c /bin/sh -c 'ape-install ||
cosmocc --update'" did not complete successfully: exit code: 2
/ #

On Tue, Sep 5, 2023 at 11:39 AM yjf_victor @.***> wrote:

Here is my test. You can have a try.

docker-cosmopolitan.zip https://github.com/jart/cosmopolitan/files/12521790/docker-cosmopolitan.zip

— Reply to this email directly, view it on GitHub https://github.com/jart/cosmopolitan/issues/287#issuecomment-1706283263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAS5V3YI3M4TEVUGZ272233XY3XN5ANCNFSM5FWVXOKA . You are receiving this because you commented.Message ID: @.***>

-- interweb homepage http://sites.google.com/site/pablomayrgundter