#!/usr/bin/env julia # --------------------------------------------------------------------------- # Build a custom system image (AOT) for the JuliaMSI MCP server. # # This bakes JuliaMSI_MCP + MSI_src (and their reachable code) into a native # shared object so the server starts without the first-call JIT latency. # # julia scripts/build_sysimage.jl # # Environment: # JULIA_MSI_PATH Path to the JuliaMSI engine checkout (default ../JuliaMSI) # JULIA_MSI_MCP_SYSIMAGE Output path (default build/sys_mcp.so) # # Run the server with the image afterwards: # julia --project=. --threads=auto --sysimage=build/sys_mcp.so bin/run_server.jl # --------------------------------------------------------------------------- using Pkg const MCP_DIR = normpath(joinpath(@__DIR__, "..")) const ENGINE = get(ENV, "JULIA_MSI_PATH", normpath(joinpath(MCP_DIR, "..", "JuliaMSI"))) const EXT = Sys.iswindows() ? ".dll" : Sys.isapple() ? ".dylib" : ".so" const OUT = get(ENV, "JULIA_MSI_MCP_SYSIMAGE", joinpath(MCP_DIR, "build", "sys_mcp" * EXT)) isfile(joinpath(ENGINE, "Project.toml")) || error("JuliaMSI engine not found at $(ENGINE). Set JULIA_MSI_PATH to the checkout.") println("--- JuliaMSI_MCP system image build ---") println("engine : ", ENGINE) println("output : ", OUT) mkpath(dirname(OUT)) # Use a throwaway environment so the runtime project stays lean. The engine is # developed first so its package name/uuid (MSI_src) resolves for JuliaMSI_MCP. Pkg.activate(; temp=true) Pkg.develop(PackageSpec(path=ENGINE)) Pkg.develop(PackageSpec(path=MCP_DIR)) Pkg.add("PackageCompiler") using PackageCompiler create_sysimage( [:JuliaMSI_MCP], sysimage_path = OUT, precompile_execution_file = joinpath(@__DIR__, "sysimage_warmup.jl"), incremental = true, ) println("--- System image written to: ", OUT, " ---") println("Run the server with:") println(" julia --project=$(MCP_DIR) --threads=auto --sysimage=$(OUT) $(joinpath(MCP_DIR, "bin", "run_server.jl"))")