mirror of
https://github.com/lune-org/lune.git
synced 2025-04-04 10:30:54 +01:00
25 lines
610 B
Text
25 lines
610 B
Text
local ffi = require("@lune/ffi")
|
|
local process = require("@lune/process")
|
|
|
|
local function getLibSuffix(): string
|
|
if process.os == "linux" then
|
|
return "so"
|
|
elseif process.os == "windows" then
|
|
return "dll"
|
|
elseif process.os == "macos" then
|
|
return "dylib"
|
|
end
|
|
error("Unknown OS")
|
|
end
|
|
|
|
local function compile(file: string): ffi.LibData
|
|
local out = file:gsub("%.c$", "." .. getLibSuffix())
|
|
local gcc = process.exec("gcc", { "-shared", "-o", out, "-fPIC", file })
|
|
if not gcc.ok then
|
|
error("Failed to execute gcc command\n" .. gcc.stdout .. gcc.stderr)
|
|
end
|
|
|
|
return ffi.open(out)
|
|
end
|
|
|
|
return compile
|