From 6810c9dd0af74edb7f7471de6fe9b62485e18c77 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 7 Oct 2025 23:23:14 +0200 Subject: [PATCH] upd2 --- .github/workflows/build_wheels.yml | 3 +-- .github/workflows/ci.yml | 41 ++++++++++++++++++----------- build.sh | 2 +- src/copapy/generate_stencils.py | 24 ++++++++++++----- src/copapy/obj/crosscompile.sh | 11 ++++---- src/copapy/obj/nativecompile.sh | 9 ++++++- src/copapy/obj/nativecompile_win.sh | 16 ----------- 7 files changed, 58 insertions(+), 48 deletions(-) delete mode 100644 src/copapy/obj/nativecompile_win.sh diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 0838cfc..9743e53 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -19,8 +19,7 @@ jobs: gcc-12-aarch64-linux-gnu \ gcc-12-arm-linux-gnueabihf \ gcc-12-mips-linux-gnu \ - gcc-12-riscv64-linux-gnu \ - mingw-w64 + gcc-12-riscv64-linux-gnu - name: Build object files run: bash src/copapy/obj/crosscompile.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 884ff01..c85219a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,21 @@ on: branches: [main] jobs: + build_stencils: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build object files + run: bash src/copapy/obj/crosscompile.sh + + - uses: actions/upload-artifact@v4 + with: + name: stencil-object-files + path: src/copapy/obj/*.o + build-ubuntu: + needs: [build_stencils] runs-on: ubuntu-latest strategy: @@ -18,15 +32,16 @@ jobs: - name: Check out code uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: stencil-object-files + path: src/copapy/obj + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Build ops obj files - run: | - bash src/copapy/obj/nativecompile.sh - - name: Install Python dependencies run: python -m pip install -e .[dev] @@ -44,12 +59,6 @@ jobs: #- name: Lint code with flake8 # run: flake8 - - uses: actions/upload-artifact@v4 - if: strategy.job-index == 0 - with: - name: stencil-object-files-linux - path: src/copapy/obj/*.o - - uses: actions/upload-artifact@v4 if: strategy.job-index == 0 with: @@ -57,6 +66,7 @@ jobs: path: bin/* build-windows: + needs: [build_stencils] runs-on: windows-latest strategy: @@ -67,6 +77,11 @@ jobs: - name: Check out code uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: stencil-object-files + path: src/copapy/obj + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -100,12 +115,6 @@ jobs: #- name: Lint code with flake8 # run: flake8 - - uses: actions/upload-artifact@v4 - if: strategy.job-index == 0 - with: - name: stencil-object-files-win - path: src/copapy/obj/*.o - - uses: actions/upload-artifact@v4 if: strategy.job-index == 0 with: diff --git a/build.sh b/build.sh index cf96fac..ac9258b 100644 --- a/build.sh +++ b/build.sh @@ -1,9 +1,9 @@ #!/bin/bash set -e set -v -python src/copapy/generate_stencils.py SRC=src/copapy/stencils.c DEST=src/copapy/obj +python src/copapy/generate_stencils.py $SRC mkdir -p $DEST gcc -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o gcc -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o diff --git a/src/copapy/generate_stencils.py b/src/copapy/generate_stencils.py index d7cf2e8..2714cb3 100644 --- a/src/copapy/generate_stencils.py +++ b/src/copapy/generate_stencils.py @@ -1,27 +1,29 @@ from typing import Generator +import argparse op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/', 'gt': '>', 'eq': '==', 'mod': '%'} +func_prefix = '' # __attribute__((ms_abi)) def get_function_start() -> str: - return """ - int function_start(){ + return f""" + {func_prefix}int function_start(){{ result_int(0); // dummy call instruction before marker gets striped asm volatile (".long 0xE2401F0F"); return 1; - } + }} """ def get_function_end() -> str: - return """ - int function_end(){ + return f""" + {func_prefix}int function_end(){{ result_int(0); asm volatile (".long 0xE1401F0F"); return 1; - } + }} """ @@ -109,6 +111,14 @@ def permutate(*lists: list[str]) -> Generator[list[str], None, None]: if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("path", type=str, help="Output file path") + parser.add_argument("--abi", type=str, default="", help="Optionaler String (Standard: '')") + args = parser.parse_args() + + if args.abi: + func_prefix = f"__attribute__(({args.abi}_abi)) " + types = ['int', 'float'] ops = ['add', 'sub', 'mul', 'div', 'gt', 'eq'] @@ -146,5 +156,5 @@ if __name__ == "__main__": code += get_function_start() + get_function_end() - with open('src/copapy/stencils.c', 'w') as f: + with open(args.path, 'w') as f: f.write(code) diff --git a/src/copapy/obj/crosscompile.sh b/src/copapy/obj/crosscompile.sh index 673192e..de0f4be 100644 --- a/src/copapy/obj/crosscompile.sh +++ b/src/copapy/obj/crosscompile.sh @@ -12,20 +12,21 @@ set -e set -v -python src/copapy/generate_stencils.py + SRC=src/copapy/stencils.c DEST=src/copapy/obj OPT=O3 + mkdir -p $DEST -x86_64-w64-mingw32-gcc --version +# Windows x86_64 (ARM64) +python src/copapy/generate_stencils.py --abi ms $SRC +gcc-12 -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o # Native x86_64 +python src/copapy/generate_stencils.py $SRC gcc-12 -$OPT -c $SRC -o $DEST/stencils_x86_64_$OPT.o -# Windows x86_64 (ARM64) -mingw-w64 -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o - # ARM64 aarch64-linux-gnu-gcc-12 -$OPT -c $SRC -o $DEST/stencils_aarch64_$OPT.o diff --git a/src/copapy/obj/nativecompile.sh b/src/copapy/obj/nativecompile.sh index 6c6f8c9..ceb59c4 100644 --- a/src/copapy/obj/nativecompile.sh +++ b/src/copapy/obj/nativecompile.sh @@ -5,10 +5,17 @@ set -v SRC=src/copapy/stencils.c DEST=src/copapy/obj -python src/copapy/generate_stencils.py +python src/copapy/generate_stencils.py $SRC mkdir -p $DEST gcc-12 -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o gcc-12 -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o gcc-12 -c $SRC -O2 -o $DEST/stencils_x86_64_O2.o gcc-12 -c $SRC -O3 -o $DEST/stencils_x86_64_O3.o + +python src/copapy/generate_stencils.py --abi ms $SRC + +gcc-12 -c $SRC -O0 -o $DEST/stencils_AMD64_O0.o +gcc-12 -c $SRC -O1 -o $DEST/stencils_AMD64_O1.o +gcc-12 -c $SRC -O2 -o $DEST/stencils_AMD64_O2.o +gcc-12 -c $SRC -O3 -o $DEST/stencils_AMD64_O3.o \ No newline at end of file diff --git a/src/copapy/obj/nativecompile_win.sh b/src/copapy/obj/nativecompile_win.sh deleted file mode 100644 index 588eb38..0000000 --- a/src/copapy/obj/nativecompile_win.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -e -set -v - -SRC=src/copapy/stencils.c -DEST=src/copapy/obj - -python src/copapy/generate_stencils.py - -mkdir -p $DEST -x86_64-w64-mingw32-gcc -c $SRC -O0 -o $DEST/stencils_AMD64_O0.o -x86_64-w64-mingw32-gcc -c $SRC -O1 -o $DEST/stencils_AMD64_O1.o -x86_64-w64-mingw32-gcc -c $SRC -O2 -o $DEST/stencils_AMD64_O2.o -x86_64-w64-mingw32-gcc -c $SRC -O3 -o $DEST/stencils_AMD64_O3.o - -x86_64-w64-mingw32-gcc --version