From 135a6ea308a98659f12d83280ebbb13d4df295f7 Mon Sep 17 00:00:00 2001 From: tqfx Date: Wed, 25 Sep 2024 09:01:33 +0800 Subject: [PATCH] create script/cargo.py --- script/cargo.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 script/cargo.py diff --git a/script/cargo.py b/script/cargo.py new file mode 100755 index 0000000..42c4cc8 --- /dev/null +++ b/script/cargo.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +import sys, os, re + +SUFFIXS = (".c", ".cc", ".cpp", ".cxx") +ROOT = os.path.abspath(sys.argv[0]) +ROOT = os.path.dirname(ROOT) +ROOT = os.path.dirname(ROOT) + + +def main(index=0, SUFFIXS=SUFFIXS): + sources = [] + for dirpath, dirnames, filenames in os.walk("src"): + for filename in filenames: + source = os.path.join(dirpath, filename) + prefix, suffix = os.path.splitext(source) + if suffix in SUFFIXS: + sources.append(source.replace("\\", "/")) + sources = sorted(sources) + + with open("build.rs", "r") as f: + build = f.read() + cur = re.findall(r"make([^;]+)\.compile\(\"a\"\)", build)[index] + new = '.file("' + '")\n .file("'.join(sources) + '")\n ' + with open("build.rs", "wb") as f: + build = f.write(build.replace(cur, new).encode()) + + +os.chdir(ROOT) +main() -- 2.11.4.GIT