|
@@ -6,11 +6,28 @@ Author: https://github.com/klivelinux
|
|
|
import os
|
|
import os
|
|
|
import sys
|
|
import sys
|
|
|
import re
|
|
import re
|
|
|
|
|
+import subprocess
|
|
|
import utils
|
|
import utils
|
|
|
import rtconfig
|
|
import rtconfig
|
|
|
from utils import _make_path_relative
|
|
from utils import _make_path_relative
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def get_zig_version():
|
|
|
|
|
+ try:
|
|
|
|
|
+ result = subprocess.run(['zig', 'version'], capture_output=True, text=True)
|
|
|
|
|
+ version_str = result.stdout.strip()
|
|
|
|
|
+ parts = version_str.split('.')
|
|
|
|
|
+ major = int(parts[0])
|
|
|
|
|
+ minor = int(parts[1]) if len(parts) > 1 else 0
|
|
|
|
|
+ return (major, minor)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ return (0, 0)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ZIG_VERSION = get_zig_version()
|
|
|
|
|
+IS_ZIG_0_14_PLUS = ZIG_VERSION[0] > 0 or (ZIG_VERSION[0] == 0 and ZIG_VERSION[1] >= 14)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def GenerateCFiles(env,project):
|
|
def GenerateCFiles(env,project):
|
|
|
info = utils.ProjectInfo(env)
|
|
info = utils.ProjectInfo(env)
|
|
|
|
|
|
|
@@ -23,12 +40,23 @@ def GenerateCFiles(env,project):
|
|
|
if zig_file:
|
|
if zig_file:
|
|
|
zig_file.write("const std = @import(\"std\");\n\n")
|
|
zig_file.write("const std = @import(\"std\");\n\n")
|
|
|
|
|
|
|
|
- zig_file.write("const target = std.zig.CrossTarget{\n")
|
|
|
|
|
- zig_file.write(" .cpu_arch = {},\n".format(ARCH))
|
|
|
|
|
- zig_file.write(" .cpu_model = .{{ .explicit = &std.Target.{}.cpu.{} }},\n".format(rtconfig.ARCH, rtconfig.CPU.replace('-', '_')))
|
|
|
|
|
- zig_file.write(" .os_tag = .freestanding,\n")
|
|
|
|
|
- zig_file.write(" .abi = .eabi,\n")
|
|
|
|
|
- zig_file.write("};\n\n")
|
|
|
|
|
|
|
+ if IS_ZIG_0_14_PLUS:
|
|
|
|
|
+ zig_file.write("const target = std.Target.Query{\n")
|
|
|
|
|
+ zig_file.write(" .cpu_arch = {},\n".format(ARCH))
|
|
|
|
|
+ zig_file.write(" .cpu_model = .{{ .explicit = &std.Target.{}.cpu.{} }},\n".format(rtconfig.ARCH, rtconfig.CPU.replace('-', '_')))
|
|
|
|
|
+ zig_file.write(" .os_tag = .freestanding,\n")
|
|
|
|
|
+ if ARCH == ".thumb":
|
|
|
|
|
+ zig_file.write(" .abi = .eabihf,\n")
|
|
|
|
|
+ else:
|
|
|
|
|
+ zig_file.write(" .abi = .eabi,\n")
|
|
|
|
|
+ zig_file.write("};\n\n")
|
|
|
|
|
+ else:
|
|
|
|
|
+ zig_file.write("const target = std.zig.CrossTarget{\n")
|
|
|
|
|
+ zig_file.write(" .cpu_arch = {},\n".format(ARCH))
|
|
|
|
|
+ zig_file.write(" .cpu_model = .{{ .explicit = &std.Target.{}.cpu.{} }},\n".format(rtconfig.ARCH, rtconfig.CPU.replace('-', '_')))
|
|
|
|
|
+ zig_file.write(" .os_tag = .freestanding,\n")
|
|
|
|
|
+ zig_file.write(" .abi = .eabi,\n")
|
|
|
|
|
+ zig_file.write("};\n\n")
|
|
|
|
|
|
|
|
zig_file.write("const c_includes = [_][]const u8{\n")
|
|
zig_file.write("const c_includes = [_][]const u8{\n")
|
|
|
for i in info['CPPPATH']:
|
|
for i in info['CPPPATH']:
|
|
@@ -60,20 +88,34 @@ def GenerateCFiles(env,project):
|
|
|
zig_file.write("};\n\n")
|
|
zig_file.write("};\n\n")
|
|
|
|
|
|
|
|
zig_file.write("pub fn build(b: *std.Build) void {\n")
|
|
zig_file.write("pub fn build(b: *std.Build) void {\n")
|
|
|
- zig_file.write(" const optimize = .ReleaseSafe;\n\n")
|
|
|
|
|
-
|
|
|
|
|
- zig_file.write(" const elf = b.addExecutable(.{\n")
|
|
|
|
|
- zig_file.write(" .name = \"rtthread.elf\",\n")
|
|
|
|
|
- zig_file.write(" .target = b.resolveTargetQuery(target),\n")
|
|
|
|
|
- zig_file.write(" .optimize = optimize,\n")
|
|
|
|
|
- zig_file.write(" .strip = false,\n")
|
|
|
|
|
- zig_file.write(" });\n\n")
|
|
|
|
|
- zig_file.write(" elf.entry = .{ .symbol_name = \"Reset_Handler\" };\n\n")
|
|
|
|
|
|
|
+ zig_file.write(" const optimize = .ReleaseSmall;\n\n")
|
|
|
|
|
+
|
|
|
|
|
+ if IS_ZIG_0_14_PLUS:
|
|
|
|
|
+ zig_file.write(" const root_module = b.createModule(.{\n")
|
|
|
|
|
+ zig_file.write(" .root_source_file = null,\n")
|
|
|
|
|
+ zig_file.write(" .target = b.resolveTargetQuery(target),\n")
|
|
|
|
|
+ zig_file.write(" .optimize = optimize,\n")
|
|
|
|
|
+ zig_file.write(" .strip = false,\n")
|
|
|
|
|
+ zig_file.write(" });\n\n")
|
|
|
|
|
+
|
|
|
|
|
+ zig_file.write(" root_module.addCSourceFiles(.{ .files = &c_sources, .flags = &c_flags });\n")
|
|
|
|
|
+ zig_file.write(" for (c_includes) |include| {\n")
|
|
|
|
|
+ zig_file.write(" root_module.addIncludePath(b.path(include));\n")
|
|
|
|
|
+ zig_file.write(" }\n\n")
|
|
|
|
|
+
|
|
|
|
|
+ zig_file.write(" const elf = b.addExecutable(.{\n")
|
|
|
|
|
+ zig_file.write(" .name = \"rtthread.elf\",\n")
|
|
|
|
|
+ zig_file.write(" .root_module = root_module,\n")
|
|
|
|
|
+ zig_file.write(" });\n\n")
|
|
|
|
|
+ else:
|
|
|
|
|
+ zig_file.write(" const elf = b.addExecutable(.{\n")
|
|
|
|
|
+ zig_file.write(" .name = \"rtthread.elf\",\n")
|
|
|
|
|
+ zig_file.write(" .target = b.resolveTargetQuery(target),\n")
|
|
|
|
|
+ zig_file.write(" .optimize = optimize,\n")
|
|
|
|
|
+ zig_file.write(" .strip = false,\n")
|
|
|
|
|
+ zig_file.write(" });\n\n")
|
|
|
|
|
|
|
|
- zig_file.write(" elf.addCSourceFiles(.{ .files = &c_sources, .flags = &c_flags });\n")
|
|
|
|
|
- zig_file.write(" for (c_includes) |include| {\n")
|
|
|
|
|
- zig_file.write(" elf.addIncludePath(b.path(include));\n")
|
|
|
|
|
- zig_file.write(" }\n\n")
|
|
|
|
|
|
|
+ zig_file.write(" elf.entry = .{ .symbol_name = \"Reset_Handler\" };\n\n")
|
|
|
|
|
|
|
|
# find link script in rtconfig.LFLAGS
|
|
# find link script in rtconfig.LFLAGS
|
|
|
LINK_SCRIPT = re.search(r'-T\s*(\S+)', LFLAGS)
|
|
LINK_SCRIPT = re.search(r'-T\s*(\S+)', LFLAGS)
|
|
@@ -93,6 +135,12 @@ def GenerateCFiles(env,project):
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
def ZigBuildProject(env,project):
|
|
def ZigBuildProject(env,project):
|
|
|
|
|
+ version_str = "{}.{}".format(ZIG_VERSION[0], ZIG_VERSION[1])
|
|
|
|
|
+ print('Detected Zig version: {}'.format(version_str))
|
|
|
|
|
+ if IS_ZIG_0_14_PLUS:
|
|
|
|
|
+ print('Using Zig 0.14+ compatible build configuration')
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('Using legacy build configuration')
|
|
|
print('Update setting files for build.zig...')
|
|
print('Update setting files for build.zig...')
|
|
|
GenerateCFiles(env,project)
|
|
GenerateCFiles(env,project)
|
|
|
print('Done!')
|
|
print('Done!')
|