import Lean import Lake open Lake DSL def evalPkgConfig (args : Array String) : IO (Array String) := do let res ← IO.Process.output { cmd := "pkg-config", args := args } if res.exitCode != 0 then throw <| IO.userError s!"pkg-config failed: {res.stderr}" return res.stdout.split Char.isWhitespace |>.map (String.Slice.toString) |>.filter (· != "") |>.toArray package «Waylean» where moreLinkArgs := #["-L.lake/build/lib", "-lCWayland"] ++ (run_io evalPkgConfig #["--libs", "wayland-client"]).filter (· != "-lm") extraDepTargets := #[`CWayland] lean_lib «WaylandScannerLib» where srcDir := "tools" roots := #[`Scanner] lean_exe «WaylandScanner» where srcDir := "tools" root := `Scanner target «WaylandProtocolsSources» pkg : Unit := do let scannerJob ← «WaylandScanner».fetch let outPath := pkg.dir / "lib" let srcPath := pkg.dir / "lib" / "Wayland" / "Protocols" / "xml" let rootModule := "Wayland.Protocols" scannerJob.bindM fun scannerFile ↦ Job.sync do proc { cmd := scannerFile.toString args := #[rootModule, outPath.toString, srcPath.toString] } target «CWayland.o» pkg : System.FilePath := do let objectFile := pkg.buildDir / "CWayland.o" let srcJob ← inputFile (text := .true) <| pkg.dir / "lib" / "CWayland" / "CWayland.cc" let cFlags ← evalPkgConfig #["--cflags", "wayland-client"] buildFileAfterDep objectFile srcJob (fun srcFile ↦ do let cFlags := cFlags ++ #["-I", (← getLeanIncludeDir).toString, "-I", (← IO.getEnv "C_INCLUDE_PATH").getD "", "-fPIC"] compileO objectFile srcFile cFlags) target «CWayland» pkg : System.FilePath := do let objectFile ← «CWayland.o».fetch let libFile := pkg.buildDir / "lib" / nameToStaticLib "CWayland" buildStaticLib libFile #[objectFile] lean_lib «Wayland» where srcDir := "lib" roots := #[`Wayland] extraDepTargets := #[`WaylandProtocolsSources] lean_lib «WayleanLib» where srcDir := "src" roots := #[`Waylean] lean_exe «Waylean» where srcDir := "src" root := `Waylean