fix syntax errors in build

This commit is contained in:
2026-02-15 09:29:07 -06:00
parent 860632e0fa
commit d9f41db891

View File

@@ -135,10 +135,11 @@ Build.compile_file = function(pkg, file, target, buildtype) {
// Add package CFLAGS (resolve relative -I paths)
arrfor(cflags, function(flag) {
if (starts_with(flag, '-I') && !starts_with(flag, '-I/')) {
flag = '-I"' + pkg_dir + '/' + text(flag, 2) + '"'
var f = flag
if (starts_with(f, '-I') && !starts_with(f, '-I/')) {
f = '-I"' + pkg_dir + '/' + text(f, 2) + '"'
}
push(cmd_parts, flag)
push(cmd_parts, f)
})
// Add target CFLAGS
@@ -196,14 +197,14 @@ Build.build_package = function(pkg, target, exclude_main, buildtype) {
// ============================================================================
// Compute link key from all inputs that affect the dylib output
function compute_link_key(objects, ldflags, target_ldflags, target, cc) {
function compute_link_key(objects, ldflags, target_ldflags, opts) {
// Sort objects for deterministic hash
var sorted_objects = sort(objects)
// Build a string representing all link inputs
var parts = []
push(parts, 'target:' + target)
push(parts, 'cc:' + cc)
push(parts, 'target:' + opts.target)
push(parts, 'cc:' + opts.cc)
arrfor(sorted_objects, function(obj) {
// Object paths are content-addressed, so the path itself is the hash
push(parts, 'obj:' + obj)
@@ -236,14 +237,15 @@ Build.build_module_dylib = function(pkg, file, target, buildtype) {
var target_ldflags = tc.c_link_args || []
var resolved_ldflags = []
arrfor(ldflags, function(flag) {
if (starts_with(flag, '-L') && !starts_with(flag, '-L/')) {
flag = '-L"' + pkg_dir + '/' + text(flag, 2) + '"'
var f = flag
if (starts_with(f, '-L') && !starts_with(f, '-L/')) {
f = '-L"' + pkg_dir + '/' + text(f, 2) + '"'
}
push(resolved_ldflags, flag)
push(resolved_ldflags, f)
})
// Content-addressed output: hash of (object + link flags + target)
var link_key = compute_link_key([obj], resolved_ldflags, target_ldflags, _target, cc)
var link_key = compute_link_key([obj], resolved_ldflags, target_ldflags, {target: _target, cc: cc})
var build_dir = get_build_dir()
ensure_dir(build_dir)
var dylib_path = build_dir + '/' + link_key + '.' + _target + dylib_ext
@@ -351,11 +353,11 @@ Build.build_static = function(packages, target, output, buildtype) {
if (!seen_flags[ldflags_key]) {
seen_flags[ldflags_key] = true
arrfor(ldflags, function(flag) {
// Resolve relative -L paths
if (starts_with(flag, '-L') && !starts_with(flag, '-L/')) {
flag = '-L"' + pkg_dir + '/' + text(flag, 2) + '"'
var f = flag
if (starts_with(f, '-L') && !starts_with(f, '-L/')) {
f = '-L"' + pkg_dir + '/' + text(f, 2) + '"'
}
push(all_ldflags, flag)
push(all_ldflags, f)
})
}
})
@@ -369,10 +371,11 @@ Build.build_static = function(packages, target, output, buildtype) {
var target_ldflags = toolchains[_target].c_link_args || []
var exe_ext = toolchains[_target].system == 'windows' ? '.exe' : ''
if (!ends_with(output, exe_ext) && exe_ext) {
output = output + exe_ext
var out_path = output
if (!ends_with(out_path, exe_ext) && exe_ext) {
out_path = out_path + exe_ext
}
var cmd_parts = [cc]
arrfor(all_objects, function(obj) {
@@ -387,18 +390,18 @@ Build.build_static = function(packages, target, output, buildtype) {
push(cmd_parts, flag)
})
push(cmd_parts, '-o', '"' + output + '"')
push(cmd_parts, '-o', '"' + out_path + '"')
var cmd_str = text(cmd_parts, ' ')
log.console('Linking ' + output)
log.console('Linking ' + out_path)
var ret = os.system(cmd_str)
if (ret != 0) {
print('Linking failed: ' + cmd_str); disrupt
}
log.console('Built ' + output)
return output
log.console('Built ' + out_path)
return out_path
}
// ============================================================================
@@ -439,6 +442,10 @@ function qbe_insert_dead_labels(il_text) {
Build.compile_native = function(src_path, target, buildtype, pkg) {
var _target = target || Build.detect_host_target()
var _buildtype = buildtype || 'release'
var qbe_rt_path = null
var native_stem = null
var native_install_dir = null
var native_install_path = null
if (!fd.is_file(src_path)) {
print('Source file not found: ' + src_path); disrupt
@@ -507,7 +514,7 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
// Step 7: Compile QBE runtime stubs if needed
if (!fd.is_file(rt_o_path)) {
var qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c'
qbe_rt_path = shop.get_package_dir('core') + '/qbe_rt.c'
rc = os.system(cc + ' -c ' + qbe_rt_path + ' -o ' + rt_o_path + ' -fPIC')
if (rc != 0) {
print('QBE runtime stubs compilation failed'); disrupt
@@ -532,10 +539,10 @@ Build.compile_native = function(src_path, target, buildtype, pkg) {
// Install to deterministic lib/<pkg>/<stem>.dylib
if (pkg) {
var native_stem = fd.stem(fd.basename(src_path))
var native_install_dir = shop.get_lib_dir() + '/' + shop.lib_name_for_package(pkg)
native_stem = fd.stem(fd.basename(src_path))
native_install_dir = shop.get_lib_dir() + '/' + shop.lib_name_for_package(pkg)
ensure_dir(native_install_dir)
var native_install_path = native_install_dir + '/' + native_stem + dylib_ext
native_install_path = native_install_dir + '/' + native_stem + dylib_ext
fd.slurpwrite(native_install_path, fd.slurp(dylib_path))
}
@@ -631,10 +638,11 @@ Build.build_all_dynamic = function(target, buildtype) {
var packages = shop.list_packages()
var results = []
var core_mods = null
// Build core first
if (find(packages, function(p) { return p == 'core' }) != null) {
var core_mods = Build.build_dynamic('core', _target, _buildtype)
core_mods = Build.build_dynamic('core', _target, _buildtype)
push(results, {package: 'core', modules: core_mods})
}