start ttf building together
This commit is contained in:
1 parent
56cab46ff4
commit
a48760a5f4
1 file changed
+56
-24
+56
-24
@@ -5,7 +5,7 @@ package SDL3
|
||||
|
||||
def sdlGitRepo : String := "https://github.com/libsdl-org/SDL.git"
|
||||
def sdlImageGitRepo : String := "https://github.com/libsdl-org/SDL_image.git"
|
||||
|
||||
def sdlTtfGitRepo : String := "https://github.com/libsdl-org/SDL_ttf.git"
|
||||
-- clone from a stable branch to avoid breakages
|
||||
def sdlBranch : String := "release-3.2.x"
|
||||
-- TODO: at some point, we should figure out a better way to set the C compiler
|
||||
@@ -21,6 +21,9 @@ target sdlDir pkg : FilePath := do
|
||||
target sdlImageDir pkg : FilePath := do
|
||||
return .pure (pkg.dir / "vendor" / "SDL_image")
|
||||
|
||||
target sdlTtfDir pkg : FilePath := do
|
||||
return .pure (pkg.dir / "vendor" / "SDL_ttf")
|
||||
|
||||
target sdl.o pkg : FilePath := do
|
||||
let srcJob ← sdl.c.fetch
|
||||
let oFile := pkg.buildDir / "c" / "sdl.o"
|
||||
@@ -34,7 +37,7 @@ target sdl.o pkg : FilePath := do
|
||||
|
||||
buildO oFile srcJob #[] #["-fPIC", s!"-I{sdlInclude}", s!"-I{sdlImageInclude}", "-D_REENTRANT", s!"-I{leanInclude}"] compiler
|
||||
|
||||
target libSDL3 pkg : Dynlib := Job.async do
|
||||
target libSDL3 : Dynlib := Job.async do
|
||||
let sdlRepoDir : FilePath ← (← sdlDir.fetch).await
|
||||
let sdlExists ← System.FilePath.pathExists sdlRepoDir
|
||||
if !sdlExists then
|
||||
@@ -68,7 +71,7 @@ target libSDL3 pkg : Dynlib := Job.async do
|
||||
-- Return built dynlib
|
||||
return {
|
||||
name := "SDL3"
|
||||
path := pkg.dir / "vendor" / "SDL" / "build" / nameToSharedLib "SDL3"
|
||||
path := sdlRepoDir / "build" / nameToSharedLib "SDL3"
|
||||
}
|
||||
|
||||
target libSDL3Image pkg : Dynlib := Job.async do
|
||||
@@ -106,9 +109,49 @@ target libSDL3Image pkg : Dynlib := Job.async do
|
||||
-- Return built dynlib
|
||||
return {
|
||||
name := "SDL3_image"
|
||||
path := pkg.dir / "vendor" / "SDL_image" / "build" / nameToSharedLib "SDL3_image"
|
||||
path := sdlImageRepoDir / "build" / nameToSharedLib "SDL3_image"
|
||||
}
|
||||
|
||||
target libSDL3Ttf pkg : Dynlib := Job.async do
|
||||
let sdlRepoDir : FilePath ← (<- sdlDir.fetch).await
|
||||
let sdlTtfRepoDir : FilePath ← (<- sdlTtfDir.fetch).await
|
||||
let sdlTtfExists ← System.FilePath.pathExists sdlTtfRepoDir
|
||||
if !sdlTtfExists then
|
||||
logInfo "Cloning SDL_ttf"
|
||||
let sdlTtfClone ← IO.Process.output { cmd := "git", args := #["clone", "-b", sdlBranch, "--single-branch", "--depth", "1", "--recursive", sdlTtfGitRepo, sdlTtfRepoDir.toString] }
|
||||
if sdlTtfClone.exitCode != 0 then
|
||||
logError s!"Error cloning SDL_ttf: {sdlTtfClone.stderr}"
|
||||
else
|
||||
logInfo "SDL_ttf cloned successfully"
|
||||
logInfo sdlTtfClone.stdout
|
||||
logInfo "Building SDL_ttf"
|
||||
-- Create build directory if it doesn't exist
|
||||
let sdlTtfBuildDirExists ← System.FilePath.pathExists (sdlTtfRepoDir / "build")
|
||||
if !sdlTtfBuildDirExists then
|
||||
-- tell SDL_ttf to vendor its own dependencies
|
||||
let configureSdlTtfBuild ← IO.Process.output { cmd := "cmake", args := #["-S", sdlTtfRepoDir.toString, "-B", (sdlTtfRepoDir / "build").toString, s!"-DSDL3_DIR={sdlRepoDir / "build"}", "-DBUILD_SHARED_LIBS=ON", "-DCMAKE_BUILD_TYPE=Release", s!"-DCMAKE_C_COMPILER={compiler}", s!"-DSDLTTF_VENDORED=true"] }
|
||||
if configureSdlTtfBuild.exitCode != 0 then
|
||||
logError s!"Error configuring SDL_ttf: {configureSdlTtfBuild.stderr}"
|
||||
else
|
||||
logInfo "SDL_ttf configured successfully"
|
||||
logInfo configureSdlTtfBuild.stdout
|
||||
else
|
||||
logInfo "SDL_ttf build directory already exists, skipping configuration step"
|
||||
-- now actually build SDL_ttf once we've configured it
|
||||
let buildSdlTtf ← IO.Process.output { cmd := "cmake", args := #["--build", (sdlTtfRepoDir / "build").toString, "--config", "Release"] }
|
||||
if buildSdlTtf.exitCode != 0 then
|
||||
logError s!"Error building SDL_ttf: {buildSdlTtf.exitCode}"
|
||||
logError buildSdlTtf.stderr
|
||||
else
|
||||
logInfo "SDL_ttf built successfully"
|
||||
logInfo buildSdlTtf.stdout
|
||||
-- Return built dynlib
|
||||
return {
|
||||
name := "SDL3_ttf"
|
||||
path := sdlTtfRepoDir / "build" / nameToSharedLib "SDL3_ttf"
|
||||
}
|
||||
|
||||
|
||||
target commonCopy : FilePath := do
|
||||
-- manually copy the DLLs we need to .lake/build/bin/ in the root directory for the game to work
|
||||
let dstDir := ((<- getRootPackage).binDir)
|
||||
@@ -133,34 +176,23 @@ target copySdlImage : Unit := do
|
||||
copyFile entry.path (dstDir / entry.path.fileName.get!)
|
||||
return pure ()
|
||||
|
||||
target copyLeanRuntime : Unit := do
|
||||
target copySdlTtf : Unit := do
|
||||
let dstDir : FilePath := (←(← commonCopy.fetch).await)
|
||||
if Platform.isWindows then
|
||||
-- binaries for Lean/Lake itself for the executable to run standalone
|
||||
let lakeBinariesDir := (← IO.appPath).parent.get!
|
||||
logInfo s!"Copying Lake DLLs from {lakeBinariesDir}"
|
||||
|
||||
for entry in (← lakeBinariesDir.readDir) do
|
||||
if entry.path.extension == some "dll" then
|
||||
copyFile entry.path (dstDir / entry.path.fileName.get!)
|
||||
else
|
||||
-- binaries for Lean/Lake itself, like libgmp are on a different place on Linux
|
||||
let lakeBinariesDir := (← IO.appPath).parent.get!.parent.get! / "lib"
|
||||
logInfo s!"Copying Lake binaries from {lakeBinariesDir}"
|
||||
|
||||
for entry in (← lakeBinariesDir.readDir) do
|
||||
if entry.path.extension != none then
|
||||
copyFile entry.path (dstDir / entry.path.fileName.get!)
|
||||
let sdlTtfDirPath ← (← sdlTtfDir.fetch).await
|
||||
let sdlTtfBinariesDir : FilePath := sdlTtfDirPath / "build"
|
||||
for entry in (← sdlTtfBinariesDir.readDir) do
|
||||
if entry.path.extension != none then
|
||||
copyFile entry.path (dstDir / entry.path.fileName.get!)
|
||||
return pure ()
|
||||
|
||||
target libleansdl pkg : FilePath := do
|
||||
discard (← libSDL3.fetch).await
|
||||
discard (← libSDL3Image.fetch).await
|
||||
discard (← libSDL3Ttf.fetch).await
|
||||
|
||||
discard (← copySdl.fetch).await
|
||||
discard (← copySdlImage.fetch).await
|
||||
-- We shouldn't need to copy the Lean runtime every time we build the library
|
||||
-- because the Lean Runtime is supposed to get statically linked already by default
|
||||
--discard (← copyLeanRuntime.fetch).await
|
||||
discard (← copySdlTtf.fetch).await
|
||||
|
||||
let sdlO ← sdl.o.fetch
|
||||
let name := nameToStaticLib "leansdl"
|
||||
|
||||
Reference in new issue
Block a user