Skip to content

Commit

Permalink
Add thirdpaty tests
Browse files Browse the repository at this point in the history
Refer to chibicc.

Include gcc headers.

Currently, success on git and lua only,
others are failed.
  • Loading branch information
tyfkda committed Sep 14, 2023
1 parent 35af483 commit 87c2e61
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ core
/dump_ir*
/dump_type*

/tests/thirdparty/.external/

### wasm

libsrc/_wasm/crt0.c
Expand Down
2 changes: 2 additions & 0 deletions src/xcc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ int main(int argc, char *argv[]) {
Vector *cpp_cmd = new_vector();
vec_push(cpp_cmd, cpp_path);
vec_push(cpp_cmd, "-D__LP64__"); // Memory model.
vec_push(cpp_cmd, "-D__STDC_NO_VLA__");
#if defined(__aarch64__)
vec_push(cpp_cmd, "-D__aarch64__");
#elif defined(__x86_64__)
Expand Down Expand Up @@ -308,6 +309,7 @@ int main(int argc, char *argv[]) {
{"D", required_argument}, // Define macro
{"o", required_argument}, // Specify output filename
{"x", required_argument}, // Specify code type
{"l", required_argument}, // Library
{"nodefaultlibs", no_argument, OPT_NODEFAULTLIBS},
{"nostdlib", no_argument, OPT_NOSTDLIB},
{"nostdinc", no_argument, OPT_NOSTDINC},
Expand Down
17 changes: 17 additions & 0 deletions tests/thirdparty/cpython.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

repo='https://github.com/python/cpython.git'
. tests/thirdparty/thirdpartycommon
git reset --hard c75330605d4795850ec74fdc4d69aa5d92f76c00

# Python's './configure' command misidentifies chibicc as icc
# (Intel C Compiler) because icc is a substring of chibicc.
# Modify the configure file as a workaround.
#sed -i -e 1996,2011d configure.ac
autoreconf

CC=$xcc ./configure
$make clean
$make
$make test
12 changes: 12 additions & 0 deletions tests/thirdparty/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

repo='https://github.com/git/git.git'
. tests/thirdparty/thirdpartycommon
git reset --hard 54e85e7af1ac9e9a92888060d6811ae767fea1bc

# CFLAGS="-D__STDC_VERSION__=199901L -Drestrict="

$make clean
$make V=1 CC="$xcc $CFLAGS"
$make V=1 CC="$xcc $CFLAGS" test
12 changes: 12 additions & 0 deletions tests/thirdparty/libpng.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

repo='https://github.com/rui314/libpng.git'
. tests/thirdparty/thirdpartycommon
git reset --hard dbe3e0c43e549a1602286144d94b0666549b18e6

CC="$xcc" ./configure
sed -i 's/^wl=.*/wl=-Wl,/; s/^pic_flag=.*/pic_flag=-fPIC/' libtool
$make clean
$make -j1
$make test
12 changes: 12 additions & 0 deletions tests/thirdparty/lua.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

repo='https://github.com/lua/lua.git'
. tests/thirdparty/thirdpartycommon
git reset --hard 6443185167c77adcc8552a3fee7edab7895db1a9 # v5.4.6

$make clean
$make -j1 CC="$xcc"

# all.lua not work
cd testes && ../lua locals.lua
14 changes: 14 additions & 0 deletions tests/thirdparty/sqlite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

repo='https://github.com/sqlite/sqlite.git'
. tests/thirdparty/thirdpartycommon
git reset --hard 86f477edaa17767b39c7bae5b67cac8580f7a8c1

CFLAGS="-D_GNU_SOURCE -D__STDC_VERSION__=199901L -Drestrict="

CC="$xcc" CFLAGS="$CFLAGS" ./configure
sed -i 's/^wl=.*/wl=-Wl,/; s/^pic_flag=.*/pic_flag=-fPIC/' libtool
$make clean
$make -j1
$make test
12 changes: 12 additions & 0 deletions tests/thirdparty/thirdpartycommon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
make="make -j$(nproc)"
xcc=$(cd "$(dirname "$0")/../../tool";pwd)/xccsh

dir=$(basename -s .git "$repo")

set -e -x

REPOROOT=$(cd "$(dirname "$0")";pwd)/.external
mkdir -p "$REPOROOT"
cd "$REPOROOT"
[ -d "$dir" ] || git clone "$repo"
cd "$dir"
11 changes: 11 additions & 0 deletions tests/thirdparty/tinycc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

repo='https://github.com/TinyCC/tinycc.git'
. tests/thirdparty/thirdpartycommon
git reset --hard df67d8617b7d1d03a480a28f9f901848ffbfb7ec

./configure --cc=$xcc
$make clean
$make
$make CC=cc test
23 changes: 23 additions & 0 deletions tool/xccsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

xcc=$(cd "$(dirname "$0")/..";pwd)/xcc

UNAME=$(uname)
ARCH=$(arch)

if [[ "$UNAME" = "Darwin" ]]; then
SYS_INCLUDE_DIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
else
SYS_INCLUDE_DIR="/usr/include/$ARCH-linux-gnu"
fi

xcc_opt="\
-fuse-ld=cc -no-pie \
-isystem /usr/include \
-isystem /usr/local/include \
-isystem $SYS_INCLUDE_DIR \
-D__signed__="

CC="$xcc $xcc_opt -D_GNU_SOURCE"

$CC "$@"

0 comments on commit 87c2e61

Please sign in to comment.