68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Compile the public module ABI as both C and C++."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HEADER = ROOT / "include"
|
|
|
|
|
|
class ModuleAbiCTests(unittest.TestCase):
|
|
def compile(self, compiler: str, suffix: str, standard: str) -> None:
|
|
with tempfile.TemporaryDirectory(
|
|
prefix="echoion-module-abi."
|
|
) as directory:
|
|
source = Path(directory) / f"consumer.{suffix}"
|
|
source.write_text(
|
|
"""
|
|
#include <echoion/api/module/ModuleAbi.h>
|
|
|
|
int main(void) {
|
|
#ifdef __cplusplus
|
|
echoion_module_descriptor_v1 descriptor = {};
|
|
#else
|
|
echoion_module_descriptor_v1 descriptor = {0};
|
|
#endif
|
|
descriptor.struct_size = sizeof(descriptor);
|
|
descriptor.abi_version = ECHOION_MODULE_ABI_VERSION;
|
|
return descriptor.api == 0 ? 0 : 1;
|
|
}
|
|
"""
|
|
)
|
|
result = subprocess.run(
|
|
[
|
|
compiler,
|
|
standard,
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-Wpedantic",
|
|
"-Werror",
|
|
"-I",
|
|
str(HEADER),
|
|
"-fsyntax-only",
|
|
str(source),
|
|
],
|
|
check=False,
|
|
text=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
def test_header_is_c11(self) -> None:
|
|
self.compile(os.environ.get("CC", "cc"), "c", "-std=c11")
|
|
|
|
def test_header_is_cpp20(self) -> None:
|
|
self.compile(os.environ.get("CXX", "c++"), "cpp", "-std=c++20")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|