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

ABI-only CI #909

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/abi-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Check if ABI-only option is correct

on: [push, pull_request]

jobs:
run-abi-only:
strategy:
matrix:
sysdeps: [dripos, lemon, aero, ironclad, lyre, keyronex]
name: Run ABI-only check
runs-on: ubuntu-20.04
steps:
- name: Install prerequisites
run: |
sudo apt-get update
sudo apt-get install ninja-build clang
sudo pip3 install setuptools
sudo pip3 install -U jsonschema
sudo pip3 install meson xbstrap
sudo pip3 install pyexpect
- name: Checkout
uses: actions/checkout@v2
with:
path: src/mlibc/
- name: Set up linux kernel headers
run: |
mkdir headers/
mkdir -p build/mlibc/
cp src/mlibc/ci/bootstrap.yml src/
cd build
xbstrap init ../src
xbstrap install linux-headers
- name: Install mlibc headers
run: |
meson setup \
-Dprefix=`realpath ../headers` \
-Dbuild_tests=false \
-Dbuild_tests_host_libc=false \
-Dheaders_only=true \
-Dlinux_kernel_headers=$(pwd)/packages/linux-headers/usr/include \
--cross-file ../src/mlibc/ci/${{matrix.sysdeps}}.cross-file compile-${{matrix.sysdeps}} \
../src/mlibc
ninja -C compile-${{matrix.sysdeps}} install
working-directory: build/
- name: Run ABI-only checker
run: |
realpath include
ls `realpath include`
python3 --version
python3 ../src/mlibc/ci/abi-only.py `realpath .`
working-directory: headers/


84 changes: 84 additions & 0 deletions ci/abi-only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import argparse
import glob
import subprocess
import os
import json
import sys

parser = argparse.ArgumentParser()
parser.add_argument("dir", help="Folder the mlibc headers are in")
args = vars(parser.parse_args())

print("Running ABI-only checker on folder '{}'.".format(args["dir"]))

headers = []
include_path = os.path.join(args["dir"], "include")
bits_path = os.path.join(include_path, "bits")

def get_all_headers(folder):
headers = list()
if not os.path.isdir(folder):
print("'{}' was expect to be a directory".format(folder))
raise TypeError()

make_abs = lambda x: os.path.join(folder, x)
files = map(make_abs, os.listdir(folder))
for f in files:
if os.path.isdir(f):
subdir_headers = get_all_headers(f)
if subdir_headers:
headers += subdir_headers
elif f.endswith(".h"):
headers.append(f)

return headers

for f in get_all_headers(include_path):
if bits_path in f:
continue
headers += [f]

command = ["clang", "-Xclang", "-ast-dump=json", "-fsyntax-only",
"-D__MLIBC_ABI_ONLY", "-includestdint.h",
"-isystem" + include_path]
full_output = []

for h in headers:
process = subprocess.run(command + [h], capture_output=True, encoding="utf-8")
full_output += [process.stdout]
print("Dumped ast from '{}'.".format(h))

def get_file_from_fn(fn):
try:
str = ", included from {}"
return str.format(fn["loc"]["includedFrom"]["file"])
except KeyError as e:
try:
str = ", declared in {}"
return str.format(fn["range"]["begin"]["expansionLoc"]["file"])
except KeyError as e:
return " from an unknown file"

seen_functions = set()
exit_code = 0
for o in full_output:
decoded = None
try:
decoded = json.loads(o)
except Exception as e:
print(o)
exit(1)

if decoded["kind"] != "TranslationUnitDecl":
print("Malformed AST dump")
exit(1)

nodes = decoded["inner"]
for n in nodes:
if n["kind"] == "FunctionDecl" and n["name"] not in seen_functions:
exit_code = 1
str = "Encountered declaration of function '{}'{}."
print(str.format(n["name"], get_file_from_fn(n)))
seen_functions.add(n["name"])

exit(exit_code)
2 changes: 2 additions & 0 deletions options/glibc/include/net/route.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _NET_ROUTE_H
#define _NET_ROUTE_H

#include <sys/socket.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
5 changes: 1 addition & 4 deletions options/linux/include/scsi/sg.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

#define SG_IO 0x2285

#define SG_DXFER_NONE (-1)
#define SG_DXFER_FROM_DEV (-3)

#define SG_FLAG_DIRECT_IO 1
#define SG_FLAG_LUN_INHIBIT 2

Expand All @@ -15,7 +12,7 @@

#define SG_DXFER_NONE -1
#define SG_DXFER_TO_DEV -2
#define SG_DXFER_TO_FROM_DEV -3
#define SG_DXFER_FROM_DEV -3
#define SG_DXFER_TO_FROM_DEV -4

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion options/posix/include/netinet/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04
#define IPTOS_LOWCOST 0x02
#define IPTOS_LOWDELAY IPTOS_LOWCOST
#define IPTOS_MINCOST IPTOS_LOWCOST
#define IPTOS_CLASS_CS4 0x80
#define IPTOS_CLASS_CS6 0xC0

Expand Down