shop audit

This commit is contained in:
2026-02-14 14:00:27 -06:00
parent e80e615634
commit 8ec56e85fa
26 changed files with 19402 additions and 19132 deletions

View File

@@ -281,6 +281,17 @@ Build.build_module_dylib = function(pkg, file, target, buildtype) {
print('Linking failed: ' + file); disrupt
}
// Install to deterministic lib/<pkg>/<stem>.dylib
var file_stem = fd.stem(file)
var install_dir = shop.get_lib_dir() + '/' + shop.lib_name_for_package(pkg)
var stem_dir = fd.dirname(file_stem)
if (stem_dir && stem_dir != '.') {
install_dir = install_dir + '/' + stem_dir
}
ensure_dir(install_dir)
var install_path = shop.get_lib_dir() + '/' + shop.lib_name_for_package(pkg) + '/' + file_stem + dylib_ext
fd.slurpwrite(install_path, fd.slurp(dylib_path))
return dylib_path
}
@@ -292,25 +303,13 @@ Build.build_dynamic = function(pkg, target, buildtype) {
var _buildtype = buildtype || 'release'
var c_files = pkg_tools.get_c_files(pkg, _target, true)
var results = []
var manifest = {}
arrfor(c_files, function(file) {
var sym_name = shop.c_symbol_for_file(pkg, file)
var dylib = Build.build_module_dylib(pkg, file, _target, _buildtype)
push(results, {file: file, symbol: sym_name, dylib: dylib})
manifest[sym_name] = dylib
})
// Write manifest so the loader can find per-module dylibs by symbol
if (length(results) > 0) {
var lib_dir = shop.get_lib_dir()
ensure_dir(lib_dir)
var lib_name = shop.lib_name_for_package(pkg)
var manifest_path = lib_dir + '/' + lib_name + '.manifest.json'
var json = use('json')
fd.slurpwrite(manifest_path, stone(blob(json.encode(manifest))))
}
return results
}
@@ -431,7 +430,7 @@ function qbe_insert_dead_labels(il_text) {
// Compile a .cm source file to a native .dylib via QBE
// Returns the content-addressed dylib path
Build.compile_native = function(src_path, target, buildtype) {
Build.compile_native = function(src_path, target, buildtype, pkg) {
var _target = target || Build.detect_host_target()
var _buildtype = buildtype || 'release'
@@ -461,7 +460,11 @@ Build.compile_native = function(src_path, target, buildtype) {
var optimized = streamline_mod(compiled)
// Step 2: Generate QBE IL
var il = qbe_emit(optimized, qbe_macros)
var sym_name = null
if (pkg) {
sym_name = shop.c_symbol_for_file(pkg, fd.basename(src_path))
}
var il = qbe_emit(optimized, qbe_macros, sym_name)
// Step 3: Post-process (insert dead labels)
il = qbe_insert_dead_labels(il)
@@ -520,6 +523,16 @@ Build.compile_native = function(src_path, target, buildtype) {
}
log.console('Built native: ' + fd.basename(dylib_path))
// 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)
ensure_dir(native_install_dir)
var native_install_path = native_install_dir + '/' + native_stem + dylib_ext
fd.slurpwrite(native_install_path, fd.slurp(dylib_path))
}
return dylib_path
}