Преглед изворни кода

verilator: switch to cmake (#5680)

* verilator: switch to cmake

* flex: fix msys

* bison: fix msys

* verilator: fix flex

* verilator: use old version

* flex: add configs for autotools

* flex: fix include

* patch mingw

* fix mingw lto

* try to fix flex for mac

* remove std=c++20 for linux

* get verbose info

* Revert "get verbose info"

This reverts commit abed7522dcb2f6af981e92014e3bd8a0f925a903.

* improve cp exe

* fix debug build on linux

* fix verilator name

* use import

* fix pacman

* add check

* default library kind

* flex: remove links

* flex: limit plat

* remove pdb copy code
star9029 пре 7 месеци
родитељ
комит
7f0e3477f6
3 измењених фајлова са 114 додато и 58 уклоњено
  1. 4 7
      packages/b/bison/xmake.lua
  2. 25 13
      packages/f/flex/xmake.lua
  3. 85 38
      packages/v/verilator/xmake.lua

+ 4 - 7
packages/b/bison/xmake.lua

@@ -20,11 +20,7 @@ package("bison")
     add_versions("3.7.6", "69dc0bb46ea8fc307d4ca1e0b61c8c355eb207d0b0c69f4f8462328e74d7b9ea")
     add_versions("3.8.2", "06c9e13bdf7eb24d4ceb6b59205a4f67c2c7e7213119644430fe82fbd14a0abb")
 
-    if is_subhost("msys") then
-        add_deps("pacman::bison")
-    end
-
-    on_load("macosx", "linux", "bsd", "windows", function (package)
+    on_load("macosx", "linux", "bsd", "windows", "@msys", function (package)
         if package:is_plat("windows") then
             package:add("deps", "winflexbison", {private = true})
         elseif package:is_plat("linux", "bsd") then
@@ -37,9 +33,10 @@ package("bison")
         if package:is_library() then
             package:set("kind", "library", {headeronly = true})
         end
-    end)
 
-    on_install("@msys", function (package)
+        if is_subhost("msys") and xmake:version():ge("2.9.7") then
+            package:add("deps", "pacman::bison", {configs = {msystem = "msys"}})
+        end
     end)
 
     on_install("windows", function (package)

+ 25 - 13
packages/f/flex/xmake.lua

@@ -1,5 +1,5 @@
 package("flex")
-    set_kind("binary")
+    set_kind("library", {headeronly = true})
     set_homepage("https://github.com/westes/flex/")
     set_license("BSD-2-Clause")
 
@@ -15,26 +15,32 @@ package("flex")
         add_urls("https://github.com/westes/flex/releases/download/v$(version)/flex-$(version).tar.gz")
     end
 
-    if is_subhost("msys") then
-        add_deps("pacman::flex")
-    end
-
-    on_load("macosx", "linux", "bsd", "windows", function (package)
+    on_load("macosx", "linux", "bsd", "windows", "@msys", function (package)
         if package:is_plat("windows") then
             package:add("deps", "winflexbison", {private = true})
         elseif package:is_plat("linux") then
             package:add("deps", "m4")
         end
 
-        -- we always set it, because flex may be modified as library
-        -- by add_deps("flex", {kind = "library"})
-        package:addenv("PATH", "bin")
-        if package:is_library() then
-            package:set("kind", "library", {headeronly = true})
+        if is_subhost("msys") and xmake:version():ge("2.9.7") then
+            package:add("deps", "pacman::flex", {private = true, configs = {msystem = "msys"}})
         end
+
+        if not package:is_cross() then
+            package:addenv("PATH", "bin")
+        end
+        -- https://github.com/Seifert69/DikuMUD3/issues/70#issuecomment-1100932157
+        -- Don't link libfl.so
+        package:add("links", "")
     end)
 
     on_install("@msys", function (package)
+        -- https://github.com/msys2/MSYS2-packages/issues/1911
+        if package:is_library() then
+            local msys_dir = os.getenv("MINGW_PREFIX")
+            local header = path.join(path.directory(msys_dir), "usr/include/FlexLexer.h")
+            os.vcp(header, package:installdir("include"))
+        end
     end)
 
     on_install("windows", function (package)
@@ -42,8 +48,14 @@ package("flex")
         os.rm(path.join(package:installdir(), "bin", "bison.exe"))
     end)
 
-    on_install("macosx", "linux", "bsd", "android", "iphoneos", "cross", function (package)
-        import("package.tools.autoconf").install(package)
+    on_install("macosx", "linux", "bsd", function (package)
+        local configs = {}
+        table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
+        table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
+        if package:is_debug() then
+            table.insert(configs, "--enable-debug")
+        end
+        import("package.tools.autoconf").install(package, configs)
     end)
 
     on_test(function (package)

+ 85 - 38
packages/v/verilator/xmake.lua

@@ -2,63 +2,110 @@ package("verilator")
     set_kind("toolchain")
     set_homepage("https://verilator.org")
     set_description("Verilator open-source SystemVerilog simulator and lint system")
+    set_license("LGPL-3.0")
 
-    add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz")
-    add_urls("https://github.com/verilator/verilator.git")
+    add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/verilator/verilator.git")
 
     add_versions("v5.016", "66fc36f65033e5ec904481dd3d0df56500e90c0bfca23b2ae21b4a8d39e05ef1")
 
+    add_deps("cmake")
+
+    if on_check then
+        on_check(function (package)
+            if is_subhost("msys") and xmake:version():lt("2.9.7") then
+                raise("package(verilator) requires xmake >= 2.9.7 on msys")
+            end
+        end)
+    end
+
     on_load(function (package)
         if not package:is_precompiled() then
-            if package:is_plat("windows") then
-                package:add("deps", "cmake")
-                package:add("deps", "winflexbison", {kind = "library"})
-            else
-                package:add("deps", "flex", {kind = "library"})
-                package:add("deps", "bison")
-                package:add("deps", "autoconf", "automake", "libtool")
-            end
+            package:add("deps", "flex", {kind = "library"})
+            package:add("deps", "bison")
             package:add("deps", "python 3.x", {kind = "binary"})
         end
         package:mark_as_pathenv("VERILATOR_ROOT")
         package:addenv("VERILATOR_ROOT", ".")
     end)
 
-    on_install("windows", function (package)
+    on_install(function (package)
         import("package.tools.cmake")
-        local configs = {}
-        local cxflags = {}
+
+        if is_subhost("msys") then
+            io.replace("CMakeLists.txt", "if(WIN32)", "if(0)", {plain = true})
+        end
+
+        local version = package:version()
+        if version then
+            if version:ge("5.030") then
+                io.replace("src/CMakeLists.txt", "MSVC_RUNTIME_LIBRARY MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>", "", {plain = true})
+            else
+                io.replace("src/CMakeLists.txt", "MSVC_RUNTIME_LIBRARY  MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>", "", {plain = true})
+                if version:lt("5.028") then
+                    if is_host("linux", "bsd") then
+                        io.replace("src/CMakeLists.txt", "install(TARGETS ${verilator})",
+                            "target_link_libraries(${verilator} PRIVATE pthread)\ninstall(TARGETS ${verilator})", {plain = true})
+                    end
+
+                    if version:lt("5.020") then
+                        if is_host("windows") and not package:has_tool("cxx", "cl") then
+                            io.replace("src/CMakeLists.txt", "INTERPROCEDURAL_OPTIMIZATION_RELEASE  TRUE", "", {plain = true})
+                            io.replace("src/CMakeLists.txt", "/bigobj", "-Wa,-mbig-obj", {plain = true})
+                            io.replace("src/CMakeLists.txt", "YY_NO_UNISTD_H", "", {plain = true})
+                            io.replace("src/CMakeLists.txt", "/STACK:10000000", "-Wl,--stack,10000000 -mconsole -lcomctl32 -DWIN_32_LEAN_AND_MEAN", {plain = true})
+                        end
+                    end
+                end
+            end
+        end
+
+        local configs = {
+            "-DOBJCACHE_ENABLED=OFF",
+            "-DDEBUG_AND_RELEASE_AND_COVERAGE=OFF",
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        if not is_host("linux") then
+            table.insert(configs, "-DCMAKE_CXX_STANDARD=20")
+        end
+
+        local opt = {}
+        opt.envs = cmake.buildenvs(package)
         local winflexbison = package:dep("winflexbison")
-        local flex = winflexbison:fetch()
-        if flex then
-            local includedirs = flex.sysincludedirs or flex.includedirs
-            for _, includedir in ipairs(includedirs) do
-                table.insert(cxflags, "-I" .. includedir)
+        if winflexbison then
+            opt.envs.WIN_FLEX_BISON = winflexbison:installdir("include")
+        else
+            local flex = package:dep("flex")
+            -- https://github.com/verilator/verilator/issues/3487
+            if is_subhost("msys") or not flex:is_system() then
+                local includedir = flex:installdir("include")
+                if version and version:lt("5.026") then
+                    opt.cxflags = "-I" .. includedir
+                else
+                    table.insert(configs, "-DFLEX_INCLUDE_DIR=" .. includedir)
+                end
             end
         end
-        local envs = cmake.buildenvs(package)
-        envs.VERILATOR_ROOT = nil
-        envs.WIN_FLEX_BISON = winflexbison:installdir()
-        io.replace("src/CMakeLists.txt", '${ASTGEN} -I"${srcdir}"', '${ASTGEN} -I "${srcdir}"', {plain = true})
-        cmake.install(package, configs, {envs = envs, cxflags = cxflags})
-        os.cp(path.join(package:installdir("bin"), "verilator_bin.exe"), path.join(package:installdir("bin"), "verilator.exe"))
-    end)
+        cmake.install(package, configs, opt)
 
-    on_install("linux", "macosx", function (package)
-        import("package.tools.autoconf")
-        local configs = {}
-        local cxflags = {}
-        local flex = package:dep("flex"):fetch()
-        if flex then
-            local includedirs = flex.sysincludedirs or flex.includedirs
-            for _, includedir in ipairs(includedirs) do
-                table.insert(cxflags, "-I" .. includedir)
+        if is_host("linux") then
+            if package:is_debug() then
+                local bindir = package:installdir("bin")
+                os.ln(path.join(bindir, "verilator_bin_dbg"), path.join(bindir, "verilator_bin"))
+            end
+        elseif is_host("windows") then
+            local bindir = package:installdir("bin")
+            local verilator = path.join(bindir, "verilator.exe")
+            if not os.isfile(verilator) then
+                local verilator_bin = "verilator_bin"
+                if package:is_debug() then
+                    verilator_bin = verilator_bin .. "_dbg"
+                end
+                verilator_bin = path.join(bindir, verilator_bin .. ".exe")
+                os.trycp(verilator_bin, verilator)
             end
         end
-        os.vrun("autoconf")
-        local envs = autoconf.buildenvs(package, {cxflags = cxflags})
-        envs.VERILATOR_ROOT = nil
-        autoconf.install(package, configs, {envs = envs})
     end)
 
     on_test(function (package)