Skip to content

Commit

Permalink
Adopt cache-apt-pkgs, add curl 8.9.1 build & unit-test to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ChAoSUnItY committed Nov 30, 2024
1 parent 84ee724 commit 7cd21e6
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 51 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/linux_thirdparty.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: praction
name: build-test-thirdparty

on: [push, pull_request]

Expand Down Expand Up @@ -33,27 +33,33 @@ jobs:
strategy:
matrix:
include:
- thirdparty: test_cello
- thirdparty: test_curl
<<<<<<< HEAD
- thirdparty: test_doom
- thirdparty: test_git
- thirdparty: test_libpng
- thirdparty: test_libuev
- thirdparty: test_lua
- thirdparty: test_metalang99
- thirdparty: test_oniguruma_jq
- thirdparty: test_openssh
- thirdparty: test_openssl
- thirdparty: test_perl
- thirdparty: test_php
- thirdparty: test_postgres
- thirdparty: test_python
- thirdparty: test_qbe_hare
- thirdparty: test_sqlite
- thirdparty: test_tinycc
- thirdparty: test_toxcore
- thirdparty: test_toybox
- thirdparty: test_vim
- thirdparty: test_zlib
- thirdparty: test_zstd
- thirdparty: build_gcc
- thirdparty: build_musl
- thirdparty: build_nano
- thirdparty: build_sdl
=======
- thirdparty: test_git
- thirdparty: test_postgres
- thirdparty: test_sqlite
- thirdparty: build_nano
>>>>>>> 2edaf33 (Initial GHA workflow for Linux thirdparty build tests)
steps:
- name: Download artifact
uses: actions/download-artifact@v4
Expand All @@ -66,6 +72,6 @@ jobs:

- name: Run test
run: >
sudo docker run
debian_asan su non-root -c
sudo docker run debian_asan
su non-root -c
'bash "$0" "$1"' linux_thirdparty.bash ${{ matrix.thirdparty }}
49 changes: 44 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Github Actions
on: [push, pull_request]

jobs:
host-x86:
host-x86-build:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -12,10 +12,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install prerequisite
run: |
sudo apt-get update -q -y
sudo apt-get install -q -y file
sudo apt-get install -q -y build-essential
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: file build-essential clang
version: 1.0
- name: Build stage 1 artifact
env:
CC: ${{ matrix.compiler }}
Expand All @@ -35,3 +35,42 @@ jobs:
run: |
make test-stage2 || exit 1
shell: bash
- run: mv slimcc slimcc-${{ matrix.compiler }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: slimcc-${{ matrix.compiler }}
path: slimcc-${{ matrix.compiler }}

test-building-real-world-projects:
needs: host-x86-build
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: slimcc-${{ matrix.compiler }}
- run: |
chmod +x slimcc-${{ matrix.compiler }}
- uses: lukka/get-cmake@latest
with:
useLocalCache: true
- name: Install prerequisite
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: file build-essential clang libssh2-1
version: 1.0
- name: Test Building curl 8.9.1
run: |
git clone --depth 1 https://github.com/curl/curl --branch curl-8_9_1
mkdir curl/cmakebuild
cd curl/cmakebuild
cmake ../ -DCMAKE_C_COMPILER=${GITHUB_WORKSPACE}/slimcc-${{ matrix.compiler }} -DCMAKE_C_FLAGS=-fPIC
make -j
make test-quiet -j
shell: bash
8 changes: 3 additions & 5 deletions hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "slimcc.h"

// Initial hash bucket size; must be power of 2
// Initial hash bucket size
#define INIT_SIZE 16

// Rehash if the usage exceeds 70%.
Expand Down Expand Up @@ -41,7 +41,6 @@ static void rehash(HashMap *map) {
HashMap map2 = {0};
map2.buckets = calloc(cap, sizeof(HashEntry));
map2.capacity = cap;
map2.mask = cap - 1;

for (int i = 0; i < map->capacity; i++) {
HashEntry *ent = &map->buckets[i];
Expand All @@ -65,7 +64,7 @@ static HashEntry *get_entry(HashMap *map, char *key, int keylen) {
uint64_t hash = fnv_hash(key, keylen);

for (int i = 0; i < map->capacity; i++) {
HashEntry *ent = &map->buckets[(hash + i) & map->mask];
HashEntry *ent = &map->buckets[(hash + i) % map->capacity];
if (match(ent, key, keylen))
return ent;
if (ent->key == NULL)
Expand All @@ -78,15 +77,14 @@ static HashEntry *get_or_insert_entry(HashMap *map, char *key, int keylen) {
if (!map->buckets) {
map->buckets = calloc(INIT_SIZE, sizeof(HashEntry));
map->capacity = INIT_SIZE;
map->mask = INIT_SIZE - 1;
} else if ((map->used * 100) / map->capacity >= HIGH_WATERMARK) {
rehash(map);
}

uint64_t hash = fnv_hash(key, keylen);

for (int i = 0; i < map->capacity; i++) {
HashEntry *ent = &map->buckets[(hash + i) & map->mask];
HashEntry *ent = &map->buckets[(hash + i) % map->capacity];

if (match(ent, key, keylen))
return ent;
Expand Down
2 changes: 1 addition & 1 deletion preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ static Token *preprocess2(Token *tok) {

for (; tok->kind != TK_EOF; pop_macro_lock(tok)) {
// If it is a macro, expand it.
if (tok->kind == TK_IDENT && expand_macro(&tok, tok))
if (expand_macro(&tok, tok))
continue;

if (is_hash(tok) && !locked_macros) {
Expand Down
12 changes: 10 additions & 2 deletions scripts/debian_asan.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc-12 \
file binutils libc-dev libgcc-12-dev \
make cmake pkg-config \
autoconf autopoint automake gettext texinfo \
git curl ca-certificates \
python3 tcl-dev bison flex re2c \
libcurl4-openssl-dev libssl-dev libexpat1-dev zlib1g-dev libicu-dev \
libncurses-dev libreadline-dev libpsl-dev libffi-dev libxml2-dev libsqlite3-dev \
# build_gcc
libgmp-dev libmpfr-dev libmpc-dev \
autoconf autopoint automake gettext texinfo
# test_toxcore
libsodium-dev \
# test_perl:cpan/Socket/t/getaddrinfo.t
netbase

COPY . /work/slimcc
WORKDIR /work/slimcc
Expand All @@ -20,8 +25,11 @@ RUN apt-get -y autoremove gcc-12 && apt-get clean
ENV ASAN_OPTIONS=detect_leaks=0
ENV CC=/work/slimcc/slimcc_asan

RUN bash scripts/linux_thirdparty.bash install_libtool

RUN useradd -m non-root -s /bin/bash && \
su non-root -c "git config --global advice.detachedHead false" && \
mv scripts/linux*.bash /home/non-root
su non-root -c "git config --global init.defaultBranch init" && \
mv scripts/linux_thirdparty.bash /home/non-root

WORKDIR /home/non-root
Loading

0 comments on commit 7cd21e6

Please sign in to comment.