build.jl (2109B)
1 # Build script: compile Nickel's C API library from source 2 # Triggered by NICKELEVAL_BUILD_FFI=true 3 4 const NICKEL_VERSION = "1.16.0" 5 const NICKEL_REPO = "https://github.com/nickel-lang/nickel.git" 6 7 function library_name() 8 if Sys.isapple() 9 return "libnickel_lang.dylib" 10 elseif Sys.iswindows() 11 return "nickel_lang.dll" 12 else 13 return "libnickel_lang.so" 14 end 15 end 16 17 function build_nickel_capi() 18 cargo = Sys.which("cargo") 19 if cargo === nothing 20 @warn "cargo not found in PATH. Install Rust: https://rustup.rs/" 21 return false 22 end 23 24 src_dir = joinpath(@__DIR__, "_nickel_src") 25 26 # Clone or update — remove stale shallow clones to avoid fetch issues 27 if isdir(src_dir) 28 rm(src_dir; recursive=true, force=true) 29 end 30 @info "Cloning Nickel $(NICKEL_VERSION)..." 31 run(`git clone --depth 1 --branch $(NICKEL_VERSION) $(NICKEL_REPO) $(src_dir)`) 32 33 @info "Building Nickel C API library..." 34 try 35 cd(src_dir) do 36 run(`cargo build --release -p nickel-lang --features capi`) 37 end 38 39 src_lib = joinpath(src_dir, "target", "release", library_name()) 40 dst_lib = joinpath(@__DIR__, library_name()) 41 42 if isfile(src_lib) 43 cp(src_lib, dst_lib; force=true) 44 @info "Library built: $(dst_lib)" 45 46 # Also generate header if cbindgen is available 47 if Sys.which("cbindgen") !== nothing 48 cd(joinpath(src_dir, "nickel")) do 49 run(`cbindgen --config cbindgen.toml --crate nickel-lang --output $(joinpath(@__DIR__, "nickel_lang.h"))`) 50 end 51 @info "Header generated: $(joinpath(@__DIR__, "nickel_lang.h"))" 52 end 53 54 return true 55 else 56 @warn "Built library not found at $(src_lib)" 57 return false 58 end 59 catch e 60 @warn "Build failed: $(e)" 61 return false 62 end 63 end 64 65 if get(ENV, "NICKELEVAL_BUILD_FFI", "false") == "true" 66 build_nickel_capi() 67 else 68 @info "Skipping FFI build (set NICKELEVAL_BUILD_FFI=true to enable)" 69 end