Skip to content

Commit

Permalink
Merge pull request #5488 from xmake-io/cosmocc
Browse files Browse the repository at this point in the history
Support to build xmake using cosmocc
  • Loading branch information
waruqi authored Aug 20, 2024
2 parents 624b853 + 594be31 commit d3effb1
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 43 deletions.
57 changes: 57 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,17 @@ path_toolname() {
emcc) toolname="emcc";;
*/em++) toolname="emxx";;
em++) toolname="emxx";;
*/cosmocc) toolname="cosmocc";;
cosmocc) toolname="cosmocc";;
*/cosmoc++) toolname="cosmocxx";;
cosmoc++) toolname="cosmocxx";;
*-ar) toolname="ar";;
*/ar) toolname="ar";;
ar) toolname="ar";;
*/emar) toolname="emar";;
emar) toolname="emar";;
*/cosmoar) toolname="cosmoar";;
cosmoar) toolname="cosmoar";;
cc) toolname="gcc";;
*/cc) toolname="gcc";;
c++) toolname="gxx";;
Expand Down Expand Up @@ -985,6 +991,8 @@ _get_abstract_flags() {
clangxx) _get_abstract_flag_for_gcc_clang "${toolkind}" "${toolname}" "${itemname}" "${value}"; flag="${_ret}";;
emcc) _get_abstract_flag_for_gcc_clang "${toolkind}" "${toolname}" "${itemname}" "${value}"; flag="${_ret}";;
emxx) _get_abstract_flag_for_gcc_clang "${toolkind}" "${toolname}" "${itemname}" "${value}"; flag="${_ret}";;
cosmocc) _get_abstract_flag_for_gcc_clang "${toolkind}" "${toolname}" "${itemname}" "${value}"; flag="${_ret}";;
cosmocxx) _get_abstract_flag_for_gcc_clang "${toolkind}" "${toolname}" "${itemname}" "${value}"; flag="${_ret}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
if test_nz "${flag}"; then
Expand Down Expand Up @@ -1702,8 +1710,11 @@ _get_target_toolchain_flags() {
clangxx) _get_target_toolchain_flags_for_clang "${name}" "${toolkind}"; flags="${_ret}";;
emcc) _get_target_toolchain_flags_for_clang "${name}" "${toolkind}"; flags="${_ret}";;
emxx) _get_target_toolchain_flags_for_clang "${name}" "${toolkind}"; flags="${_ret}";;
cosmocc) _get_target_toolchain_flags_for_gcc "${name}" "${toolkind}"; flags="${_ret}";;
cosmocxx) _get_target_toolchain_flags_for_gcc "${name}" "${toolkind}"; flags="${_ret}";;
ar) _get_target_toolchain_flags_for_ar "${name}" "${toolkind}"; flags="${_ret}";;
emar) _get_target_toolchain_flags_for_ar "${name}" "${toolkind}"; flags="${_ret}";;
cosmoar) _get_target_toolchain_flags_for_ar "${name}" "${toolkind}"; flags="${_ret}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
_ret="${flags}"
Expand Down Expand Up @@ -2719,6 +2730,7 @@ Common options:
- mingw
- macosx
- linux
- wasm
--arch=ARCH Compile for the given architecture. (default: '"${_target_arch_default}"')
- msys: i386 x86_64
- cross: i386 x86_64 arm arm64 mips mips64 riscv riscv64 loong64 s390x ppc ppc64 sh4
Expand All @@ -2736,6 +2748,8 @@ Common options:
--toolchain=TOOLCHAIN Set toolchain name.
- clang
- gcc
- emcc
- cosmocc
--buildir=DIR Set build directory. (default: '"${xmake_sh_buildir}"')
Autoconf options:
Expand Down Expand Up @@ -3027,6 +3041,18 @@ toolchain "emcc"
set_toolset "ar" "emar" "ar"
toolchain_end

# cosmocc toolchain, e.g. ./configure --plat=linux --toolchain=cosmocc
toolchain "cosmocc"
set_toolset "as" "cosmocc"
set_toolset "cc" "cosmocc"
set_toolset "cxx" "cosmocc" "cosmoc++"
set_toolset "mm" "cosmocc"
set_toolset "mxx" "cosmocc" "cosmoc++"
set_toolset "ld" "cosmoc++" "cosmocc"
set_toolset "sh" "cosmoc++" "cosmocc"
set_toolset "ar" "cosmoar"
toolchain_end

# check platform
_check_platform() {
if test "x${_target_plat}" = "x"; then
Expand Down Expand Up @@ -3093,6 +3119,8 @@ _toolchain_compcmd() {
clangxx) _toolchain_compcmd_for_gcc_clang "${program}" "${objectfile}" "${sourcefile}" "${flags}"; compcmd="${_ret}";;
emcc) _toolchain_compcmd_for_gcc_clang "${program}" "${objectfile}" "${sourcefile}" "${flags}"; compcmd="${_ret}";;
emxx) _toolchain_compcmd_for_gcc_clang "${program}" "${objectfile}" "${sourcefile}" "${flags}"; compcmd="${_ret}";;
cosmocc) _toolchain_compcmd_for_gcc_clang "${program}" "${objectfile}" "${sourcefile}" "${flags}"; compcmd="${_ret}";;
cosmocxx) _toolchain_compcmd_for_gcc_clang "${program}" "${objectfile}" "${sourcefile}" "${flags}"; compcmd="${_ret}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
_ret="${compcmd}"
Expand All @@ -3113,8 +3141,11 @@ _toolchain_linkcmd() {
clangxx) _toolchain_linkcmd_for_gcc_clang "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
emcc) _toolchain_linkcmd_for_gcc_clang "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
emxx) _toolchain_linkcmd_for_gcc_clang "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
cosmocc) _toolchain_linkcmd_for_gcc_clang "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
cosmocxx) _toolchain_linkcmd_for_gcc_clang "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
ar) _toolchain_linkcmd_for_ar "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
emar) _toolchain_linkcmd_for_ar "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
cosmoar) _toolchain_linkcmd_for_ar "${toolkind}" "${program}" "${binaryfile}" "${objectfiles}" "${flags}"; linkcmd="${_ret}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
_ret="${linkcmd}"
Expand Down Expand Up @@ -3237,6 +3268,24 @@ _toolchain_try_ar() {
return 1
}

# try cosmoar
_toolchain_try_cosmoar() {
if test "x${_toolchain_try_cosmoar_result}" = "xok"; then
return 0
elif test "x${_toolchain_try_cosmoar_result}" = "xno"; then
return 1
fi

local kind="${1}"
local program="${2}"
if _os_runv "${program}" "--version"; then
_toolchain_try_cosmoar_result="ok"
return 0
fi
_toolchain_try_cosmoar_result="no"
return 1
}

# try program
_toolchain_try_program() {
local toolchain="${1}"
Expand All @@ -3251,8 +3300,11 @@ _toolchain_try_program() {
clangxx) _toolchain_try_clangxx "${kind}" "${program}" && ok=true;;
emcc) _toolchain_try_clang "${kind}" "${program}" && ok=true;;
emxx) _toolchain_try_clangxx "${kind}" "${program}" && ok=true;;
cosmocc) _toolchain_try_gcc "${kind}" "${program}" && ok=true;;
cosmocxx) _toolchain_try_gxx "${kind}" "${program}" && ok=true;;
ar) _toolchain_try_ar "${kind}" "${program}" && ok=true;;
emar) _toolchain_try_ar "${kind}" "${program}" && ok=true;;
cosmoar) _toolchain_try_cosmoar "${kind}" "${program}" && ok=true;;
*) raise "unknown toolname(${toolname})!" ;;
esac
if ${ok}; then
Expand Down Expand Up @@ -3982,6 +4034,8 @@ _gmake_add_build_object() {
clangxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";;
emcc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";;
emxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";;
cosmocc) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";;
cosmocxx) _gmake_add_build_object_for_gcc_clang "${sourcekind}" "${sourcefile}" "${objectfile}" "${flagname}";;
*) raise "unknown toolname(${toolname})!" ;;
esac
echo "" >> "${xmake_sh_makefile}"
Expand Down Expand Up @@ -4062,8 +4116,11 @@ _gmake_add_build_target() {
clangxx) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
emcc) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
emxx) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
cosmocc) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
cosmocxx) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
ar) _gmake_add_build_target_for_ar "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
emar) _gmake_add_build_target_for_ar "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
cosmoar) _gmake_add_build_target_for_ar "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
*) raise "unknown toolname(${toolname})!" ;;
esac

Expand Down
21 changes: 17 additions & 4 deletions core/src/tbox/inc/linux/tbox.config.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,13 @@
#define TB_CONFIG_POSIX_HAVE_FDATASYNC 1
/* #undef TB_CONFIG_POSIX_HAVE_COPYFILE */
#define TB_CONFIG_POSIX_HAVE_SENDFILE 1
#define TB_CONFIG_POSIX_HAVE_EPOLL_CREATE 1
#define TB_CONFIG_POSIX_HAVE_EPOLL_WAIT 1
#ifdef __COSMOPOLITAN__
/* #undef TB_CONFIG_POSIX_HAVE_EPOLL_CREATE */
/* #undef TB_CONFIG_POSIX_HAVE_EPOLL_WAIT */
#else
# define TB_CONFIG_POSIX_HAVE_EPOLL_CREATE 1
# define TB_CONFIG_POSIX_HAVE_EPOLL_WAIT 1
#endif
#if defined(__ANDROID__)
/* #undef TB_CONFIG_POSIX_HAVE_POSIX_SPAWNP */
#else
Expand All @@ -196,7 +201,11 @@
#define TB_CONFIG_POSIX_HAVE_FCNTL 1
#define TB_CONFIG_POSIX_HAVE_PIPE 1
/* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */
#define TB_CONFIG_POSIX_HAVE_MKFIFO 1
#ifdef __COSMOPOLITAN__
/* #undef TB_CONFIG_POSIX_HAVE_MKFIFO */
#else
# define TB_CONFIG_POSIX_HAVE_MKFIFO 1
#endif
#define TB_CONFIG_POSIX_HAVE_FUTIMENS 1
#define TB_CONFIG_POSIX_HAVE_UTIMENSAT 1

Expand All @@ -211,6 +220,10 @@
/* #undef TB_CONFIG_SYSTEMV_HAVE_VALGRIND_STACK_REGISTER */

// linux functions
#define TB_CONFIG_LINUX_HAVE_INOTIFY_INIT 1
#ifdef __COSMOPOLITAN__
/* #undef TB_CONFIG_LINUX_HAVE_INOTIFY_INIT */
#else
# define TB_CONFIG_LINUX_HAVE_INOTIFY_INIT 1
#endif

#endif
2 changes: 1 addition & 1 deletion xmake/core/base/fwatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ end
-- ensure the fwatcher is opened
function _instance:_ensure_opened()
if not self:cdata() then
return false, string.format("%s: has been closed!", self)
return false, string.format("<fwatcher:%s>: has been closed!", self:cdata())
end
return true
end
Expand Down
Loading

0 comments on commit d3effb1

Please sign in to comment.