Add Cosmopolitan Libc Platform (#2598)
This PR adds the Cosmopolitan Libc platform enabling compatibility with multiple x86_64 operating systems with the same binary. The platform is similar to the Linux platform, but for now only x86_64 with interpreter modes are supported. The only major change to the core is `posix.c/convert_errno()` was rewritten to use a switch statement. With Cosmopolitan errno values depend on the currently running operating system, and so they are non-constant and cannot be used in array designators. However, the `cosmocc` compiler allows non-constant case labels in switch statements, enabling the new version. And updated wamr-test-suites script to add `-j <platform>` option. The spec tests can be ran via `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t classic-interp` or `CC=cosmocc ./test_wamr.sh -j cosmopolitan -t fast-interp`.
This commit is contained in:
@ -31,6 +31,7 @@ function help()
|
||||
echo "-Q enable qemu"
|
||||
echo "-F set the firmware path used by qemu"
|
||||
echo "-C enable code coverage collect"
|
||||
echo "-j set the platform to test"
|
||||
}
|
||||
|
||||
OPT_PARSED=""
|
||||
@ -58,7 +59,7 @@ QEMU_FIRMWARE=""
|
||||
# prod/testsuite-all branch
|
||||
WASI_TESTSUITE_COMMIT="cf64229727f71043d5849e73934e249e12cb9e06"
|
||||
|
||||
while getopts ":s:cabgvt:m:MCpSXxwPGQF:" opt
|
||||
while getopts ":s:cabgvt:m:MCpSXxwPGQF:j:" opt
|
||||
do
|
||||
OPT_PARSED="TRUE"
|
||||
case $opt in
|
||||
@ -160,6 +161,10 @@ do
|
||||
echo "QEMU firmware" ${OPTARG}
|
||||
QEMU_FIRMWARE=${OPTARG}
|
||||
;;
|
||||
j)
|
||||
echo "test platform " ${OPTARG}
|
||||
PLATFORM=${OPTARG}
|
||||
;;
|
||||
?)
|
||||
help
|
||||
exit 1;;
|
||||
@ -383,6 +388,8 @@ function spec_test()
|
||||
local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
|
||||
if [ ! -f ${WAT2WASM} ]; then
|
||||
case ${PLATFORM} in
|
||||
cosmopolitan)
|
||||
;&
|
||||
linux)
|
||||
WABT_PLATFORM=ubuntu
|
||||
;;
|
||||
@ -656,6 +663,20 @@ function build_iwasm_with_cfg()
|
||||
echo -e "build iwasm failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${PLATFORM} == "cosmopolitan" ]]; then
|
||||
# convert from APE to ELF so it can be ran easier
|
||||
# HACK: link to linux so tests work when platform is detected by uname
|
||||
cp iwasm.com iwasm \
|
||||
&& ./iwasm --assimilate \
|
||||
&& rm -rf ../../linux/build \
|
||||
&& mkdir ../../linux/build \
|
||||
&& ln -s ../../cosmopolitan/build/iwasm ../../linux/build/iwasm
|
||||
if [ "$?" != 0 ];then
|
||||
echo -e "build iwasm failed (cosmopolitan)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function build_wamrc()
|
||||
|
||||
Reference in New Issue
Block a user