compilation
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
var os = use('os')
|
||||
var fd = use('fd')
|
||||
|
||||
if (!fd.is_dir('.cell'))
|
||||
fd.mkdir('.cell')
|
||||
|
||||
var shop = use('shop')
|
||||
var config = shop.load_config()
|
||||
|
||||
function get_flags(config, platform, key) {
|
||||
var flags = ''
|
||||
if (config.compilation && config.compilation[key]) {
|
||||
flags += config.compilation[key]
|
||||
}
|
||||
if (config.compilation && config.compilation[platform] && config.compilation[platform][key]) {
|
||||
if (flags != '') flags += ' '
|
||||
flags += config.compilation[platform][key]
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
||||
var files = fd.enumerate('.', true)
|
||||
var objects = []
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i]
|
||||
if (file.endsWith('.c') || file.endsWith('.cpp')) {
|
||||
var path_no_ext = file.substring(0, file.lastIndexOf('.'))
|
||||
var safe_path = path_no_ext.replace(/\//g, '_').replace(/\\/g, '_')
|
||||
if (safe_path.startsWith('._')) safe_path = safe_path.substring(2)
|
||||
|
||||
var use_name = 'js_local_' + safe_path + '_use'
|
||||
|
||||
var obj_file = '.cell/build/' + file + '.o'
|
||||
var last_slash = file.lastIndexOf('/')
|
||||
if (last_slash != -1) {
|
||||
var dir = '.cell/build/' + file.substring(0, last_slash)
|
||||
if (!fd.is_dir(dir))
|
||||
obj_file = '.cell/build/' + safe_path + '.o'
|
||||
} else {
|
||||
obj_file = '.cell/build/' + file + '.o'
|
||||
}
|
||||
|
||||
objects.push(obj_file)
|
||||
|
||||
var needs_compile = true
|
||||
if (fd.is_file(obj_file)) {
|
||||
try {
|
||||
var src_stat = fd.stat(file)
|
||||
var obj_stat = fd.stat(obj_file)
|
||||
var src_time = src_stat.modtime ?? src_stat.mtime
|
||||
var obj_time = obj_stat.modtime ?? obj_stat.mtime
|
||||
if (src_time != null && obj_time != null && obj_time >= src_time) {
|
||||
needs_compile = false
|
||||
}
|
||||
} catch (e) {
|
||||
needs_compile = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!needs_compile) {
|
||||
log.console("Skipping " + file + " (up to date)")
|
||||
} else {
|
||||
log.console("Compiling " + file + " -> " + obj_file)
|
||||
log.console(`export name is ${use_name}`)
|
||||
|
||||
// Compile command
|
||||
// cc -fPIC -c <file> -O3 -DCELL_USE_NAME=<name> -o <obj_file>
|
||||
var cmd = 'cc -fPIC -c ' + file + ' -O3 -DCELL_USE_NAME=' + use_name + ' -o ' + obj_file
|
||||
var cflags = get_flags(config, os.platform(), 'CFLAGS')
|
||||
if (cflags != '') cmd += ' ' + cflags
|
||||
|
||||
var ret = os.system(cmd)
|
||||
if (ret != 0) {
|
||||
log.console("Compilation failed for " + file)
|
||||
$_.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there are any object files to link
|
||||
if (objects.length == 0) {
|
||||
log.console("No object files found, skipping linking.")
|
||||
log.console("Build complete: no shared library created")
|
||||
$_.stop()
|
||||
return
|
||||
}
|
||||
|
||||
// 4. Link shared library
|
||||
var lib_ext = '.so'
|
||||
var link_flags = '-shared'
|
||||
if (os.platform() == 'macOS') {
|
||||
lib_ext = '.dylib'
|
||||
link_flags = '-shared'
|
||||
} else if (os.platform() == 'Windows') {
|
||||
lib_ext = '.dll'
|
||||
}
|
||||
|
||||
// Ensure .cell/local exists
|
||||
if (!fd.is_dir('.cell/local'))
|
||||
fd.mkdir('.cell/local')
|
||||
|
||||
var lib_name = '.cell/local/local' + lib_ext
|
||||
log.console("Linking " + lib_name)
|
||||
|
||||
var ldflags = get_flags(config, os.platform(), 'LDFLAGS')
|
||||
if (ldflags != '') link_flags += ' ' + ldflags
|
||||
|
||||
var link_cmd = 'cc ' + link_flags + ' ' + objects.join(' ') + ' -lcell -lc -lc++ -o ' + lib_name
|
||||
var ret = os.system(link_cmd)
|
||||
|
||||
if (ret != 0) {
|
||||
log.console("Linking failed")
|
||||
$_.stop()
|
||||
}
|
||||
|
||||
log.console("Build complete: " + lib_name)
|
||||
|
||||
$_.stop()
|
||||
@@ -33,7 +33,7 @@ var js = use_embed('js')
|
||||
var use_cache = {}
|
||||
|
||||
function use_core(path) {
|
||||
var cache_path = `2:${path}`;
|
||||
var cache_path = `2::${path}`;
|
||||
if (use_cache[cache_path])
|
||||
return use_cache[cache_path];
|
||||
|
||||
|
||||
@@ -450,9 +450,6 @@ JSC_CCALL(fd_slurpwrite,
|
||||
if (data == (const char *)-1)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
if (len == 0)
|
||||
return JS_ThrowTypeError(js, "No data provided to write");
|
||||
|
||||
const char *str = JS_ToCString(js, argv[0]);
|
||||
|
||||
if (!str) return JS_EXCEPTION;
|
||||
|
||||
@@ -20,6 +20,7 @@ if (args && args.length > 0) {
|
||||
}
|
||||
|
||||
var deps = shop.dependencies(ctx)
|
||||
log.console(json.encode(deps))
|
||||
if (target_alias) {
|
||||
log.console("Dependencies for " + pkg_name + ":")
|
||||
} else {
|
||||
|
||||
@@ -383,7 +383,7 @@ static JSValue js_os_dylib_symbol(JSContext *js, JSValue self, int argc, JSValue
|
||||
error_msg = dl_error;
|
||||
}
|
||||
#endif
|
||||
return JS_ThrowReferenceError(js, "Failed to get symbol: %s", error_msg);
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
// Return the symbol as a pointer value
|
||||
|
||||
691
scripts/shop.cm
691
scripts/shop.cm
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user