Răsfoiți Sursa

add verilator (#1735)

* add verilator

* improve flex deps

* improve flex deps for windows

* improve bison and flex

* improve bison and flex

* use winbisonflex

* improve flex

* improve flex

* fix astgen

* fix astgen

* fix include flex

* fix include flex

* fix include flex

* fix bison deps

* add dump

* fix bin
ruki 2 ani în urmă
părinte
comite
c141f85a27

+ 10 - 11
packages/b/bison/xmake.lua

@@ -1,5 +1,4 @@
 package("bison")
-
     set_kind("binary")
     set_homepage("https://www.gnu.org/software/bison/")
     set_description("A general-purpose parser generator.")
@@ -14,26 +13,26 @@ package("bison")
     add_versions("3.8.2", "06c9e13bdf7eb24d4ceb6b59205a4f67c2c7e7213119644430fe82fbd14a0abb")
 
     if is_plat("windows") then
-        add_deps("winflexbison")
+        add_deps("winflexbison", {private = true})
     elseif is_plat("linux", "bsd") then
         add_deps("m4")
     end
 
-    on_load(function (package)
-        if package:is_plat("windows") then
-            -- handled by winflexbison
-            return
-        end
+    on_load("macosx", "linux", "bsd", "windows", function (package)
+        -- we always set it, because flex may be modified as library
+        -- by add_deps("bison", {kind = "library"})
         package:addenv("PATH", "bin")
     end)
 
     on_install(function (package)
         if package:is_plat("windows") then
-            -- handled by winflexbison
-            return
+            os.cp(path.join(package:dep("winflexbison"):installdir(), "*"), package:installdir())
+            os.rm(path.join(package:installdir(), "bin", "flex.exe"))
+            os.rm(path.join(package:installdir(), "include", "FlexLexer.h"))
+        else
+            import("package.tools.autoconf").install(package)
+            os.rm(package:installdir("share", "doc"))
         end
-        import("package.tools.autoconf").install(package)
-        os.rm(package:installdir("share", "doc"))
     end)
 
     on_test(function (package)

+ 15 - 5
packages/f/flex/xmake.lua

@@ -1,5 +1,4 @@
 package("flex")
-
     set_kind("binary")
     set_homepage("https://github.com/westes/flex/")
     set_license("BSD-2-Clause")
@@ -11,23 +10,34 @@ package("flex")
     add_versions("2.6.4", "e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995")
 
     if is_plat("windows") then
-        add_deps("winflexbison")
+        add_deps("winflexbison", {private = true})
     elseif is_plat("linux") then
         add_deps("m4")
     end
 
-    on_load("macosx", "linux", "bsd", "android", "iphoneos", "cross", function (package)
+    on_load("macosx", "linux", "bsd", "windows", function (package)
+        -- we always set it, because flex may be modified as library
+        -- by add_deps("flex", {kind = "library"})
         package:addenv("PATH", "bin")
     end)
 
     on_install("windows", function (package)
-        -- handled by winflexbison
+        os.cp(path.join(package:dep("winflexbison"):installdir(), "*"), package:installdir())
+        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)
+        if not package:is_binary() then
+            package:add("links", "")
+        end
     end)
 
     on_test(function (package)
-        os.vrun("flex -h")
+        if not package:is_cross() then
+            os.vrun("flex -h")
+        end
+        if not package:is_binary() then
+            assert(package:has_cxxincludes("FlexLexer.h"))
+        end
     end)

+ 62 - 0
packages/v/verilator/xmake.lua

@@ -0,0 +1,62 @@
+package("verilator")
+    set_kind("toolchain")
+    set_homepage("https://verilator.org")
+    set_description("Verilator open-source SystemVerilog simulator and lint system")
+
+--    add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz")
+    add_urls("https://github.com/verilator/verilator.git")
+    add_versions("2023.1.10", "5fce23e90d2a721bb712dc9aacde594558489dda")
+
+    -- wait for next release with cmake
+--    add_versions("v5.004", "7d193a09eebefdbec8defaabfc125663f10cf6ab0963ccbefdfe704a8a4784d2")
+
+    if is_plat("windows") then
+        add_deps("winflexbison", {kind = "library"})
+    else
+        add_deps("flex", {kind = "library"})
+        add_deps("bison")
+    end
+    add_deps("python 3.x", {kind = "binary"})
+
+    if is_plat("windows") then
+        add_deps("cmake")
+    else
+        add_deps("autoconf", "automake", "libtool")
+    end
+
+    on_install("windows", function (package)
+        import("package.tools.cmake")
+        local configs = {}
+        local cxflags = {}
+        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)
+            end
+        end
+        local envs = cmake.buildenvs(package)
+        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)
+
+    on_install("linux", "macosx", function (package)
+        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)
+            end
+        end
+        os.vrun("autoconf")
+        import("package.tools.autoconf").install(package, configs, {cxflags = cxflags})
+    end)
+
+    on_test(function (package)
+        os.vrun("verilator --version")
+    end)

+ 23 - 7
packages/w/winflexbison/xmake.lua

@@ -9,9 +9,14 @@ package("winflexbison")
 
     add_versions("v2.5.25", "8e1b71e037b524ba3f576babb0cf59182061df1f19cd86112f085a882560f60b")
 
+    add_configs("flex", {description = "Enable flex", default = true, type = "boolean"})
+    add_configs("bison", {description = "Enable bison", default = true, type = "boolean"})
+
     add_deps("cmake")
 
     on_load(function (package)
+        -- we always set it, because flex may be modified as library
+        -- by add_deps("winflexbison", {kind = "library"})
         package:addenv("PATH", "bin")
     end)
 
@@ -20,14 +25,25 @@ package("winflexbison")
         local configs = {}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. mode)
         import("package.tools.cmake").build(package, configs)
-        os.mv("custom_build_rules", package:installdir("bin"))
-        os.mv("flex/src/FlexLexer.h", package:installdir("include"))
-        os.mv(path.join("bin", mode, "*"), package:installdir("bin"))
-        os.cp(path.join(package:installdir("bin"), "win_bison.exe"), path.join(package:installdir("bin"), "bison.exe"))
-        os.cp(path.join(package:installdir("bin"), "win_flex.exe"), path.join(package:installdir("bin"), "flex.exe"))
+        os.cp("custom_build_rules", package:installdir("bin"))
+        os.cp(path.join("bin", mode, "*"), package:installdir("bin"))
+        if package:config("flex") then
+            os.cp("flex/src/FlexLexer.h", package:installdir("include"))
+            os.cp(path.join(package:installdir("bin"), "win_flex.exe"), path.join(package:installdir("bin"), "flex.exe"))
+        end
+        if package:config("bison") then
+            os.cp(path.join(package:installdir("bin"), "win_bison.exe"), path.join(package:installdir("bin"), "bison.exe"))
+        end
     end)
 
     on_test(function (package)
-        os.vrun("win_bison.exe -h")
-        os.vrun("win_flex.exe -h")
+        if package:config("bison") then
+            os.vrun("bison.exe -h")
+        end
+        if package:config("flex") then
+            os.vrun("flex.exe -h")
+            if not package:is_binary() then
+                assert(package:has_cxxincludes("FlexLexer.h"))
+            end
+        end
     end)