Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cosmocc toolchain support #4709

Closed
8 tasks done
waruqi opened this issue Feb 6, 2024 · 1 comment
Closed
8 tasks done

Add cosmocc toolchain support #4709

waruqi opened this issue Feb 6, 2024 · 1 comment

Comments

@waruqi
Copy link
Member

waruqi commented Feb 6, 2024

build-once run-anywhere

https://github.com/jart/cosmopolitan

Roadmap

#4704

  • download and use cosmocc toolchain automatically
  • support projects
    • console
    • static library
  • support platforms
    • windows/msys2
    • linux
    • macosx

Example projects

see https://github.com/xmake-io/xmake/tree/master/tests/projects/c/cosmocc

Console

add_rules("mode.debug", "mode.release")

add_requires("cosmocc")

target("test")
    set_kind("binary")
    add_files("src/*.c")
    set_toolchains("@cosmocc")

Static library

add_rules("mode.release", "mode.debug")

add_requires("cosmocc")
set_toolchains("@cosmocc")

target("foo")
    set_kind("static")
    add_files("src/foo.c")

target("demo")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.c")

Linux

ruki:console$ xmake 
checking for platform ... linux
checking for architecture ... x86_64
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> cosmocc 3.2.4 
please input: y (y/n/m)

  => install cosmocc 3.2.4 .. ok   
[ 25%]: cache compiling.release src/main.c
[ 50%]: linking.release test
[100%]: build ok, spent 1.548s
ruki:console$ xmake run
hello world
ruki:console$ xmake -v
[ 25%]: cache compiling.release src/main.c
/home/ruki/.xmake/packages/c/cosmocc/3.2.4/f3d565918c3c4585af8de6edefe141a3/bin/cosmocc -c -fvisibility=hidden -O3 -DNDEBUG -o build/.objs/test/linux/x86_64/release/src/main.c.o src/main.c
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
checking for cosmoc++ ... /home/ruki/.xmake/packages/c/cosmocc/3.2.4/f3d565918c3c4585af8de6edefe141a3/bin/cosmoc++
checking for the linker (ld) ... cosmoc++
checking for /home/ruki/.xmake/packages/c/cosmocc/3.2.4/f3d565918c3c4585af8de6edefe141a3/bin/cosmoc++ ... ok
checking for flags (-fPIC) ... ok
[ 50%]: linking.release test
/home/ruki/.xmake/packages/c/cosmocc/3.2.4/f3d565918c3c4585af8de6edefe141a3/bin/cosmoc++ -o build/linux/x86_64/release/test build/.objs/test/linux/x86_64/release/src/main.c.o
[100%]: build ok, spent 1.652s

Windows/Msys2

We need to run cosmocc on Msys2, because cosmocc is a shell script, it need to run bash/sh.

wangrunqing@IIGS-A8825-D MINGW64 /d/projects/personal/xmake/tests/projects/c/cosmocc/console
$ xmake
checking for platform ... mingw
checking for architecture ... x86_64
checking for mingw directory ... C:/msys64/mingw64
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> cosmocc 3.2.4
please input: y (y/n/m)

  => download https://github.com/xmake-mirror/cosmopolitan/releases/download/3.2.4/cosmocc-3.2.4.zip .. ok
  => install cosmocc 3.2.4 .. ok
[ 25%]: cache compiling.release src\main.c
[ 50%]: linking.release test.exe
[100%]: build ok, spent 9.453s

wangrunqing@IIGS-A8825-D MINGW64 /d/projects/personal/xmake/tests/projects/c/cosmocc/console
$ xmake run
hello world

MacOS

ruki:static_library ruki$ xmake
checking for platform ... macosx
checking for architecture ... x86_64
checking for Xcode directory ... /Applications/Xcode.app
checking for Codesign Identity of Xcode ... Apple Development: waruqi@gmail.com (T3NA4MRVPU)
checking for SDK version of Xcode for macosx (x86_64) ... 14.0
checking for Minimal target version of Xcode for macosx (x86_64) ... 14.0
[ 25%]: cache compiling.release src/foo.c
[ 25%]: cache compiling.release src/main.c
[ 50%]: archiving.release libfoo.a
[ 75%]: linking.release demo
[100%]: build ok, spent 3.099s
ruki:static_library ruki$ xmake run
add(1, 2) = 3
@waruqi waruqi added this to the v2.8.7 milestone Feb 6, 2024
@waruqi waruqi closed this as completed Feb 6, 2024
@waruqi
Copy link
Member Author

waruqi commented Feb 7, 2024

I have added cosmocc package for windows. xmake-io/xmake-repo#3248

But we need to install sh/bash and update xmake/core to dev version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant