Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verilator: switch to cmake #5680

Merged
merged 23 commits into from
Dec 13, 2024
Merged

verilator: switch to cmake #5680

merged 23 commits into from
Dec 13, 2024

Conversation

star-hengxing
Copy link
Contributor

@star-hengxing star-hengxing commented Nov 6, 2024

A new packaging method:
We can directly use pacman::flex/bison as xmake::flex/bison deps on msys2 subhost.

        if is_subhost("msys") and xmake:version():ge("2.9.7") then
            package:add("deps", "pacman::bison", {configs = {msystem = "msys"}})
        end
  • flex
    • binary kind by default before, now set_kind("library", {headeronly = true})
    • Copy pacman::flex header file usr/include/FlexLexer.h to package:installdir("include")
    • Remove flex links.
  • verilator
    • Romove autotools build support.

@star-hengxing star-hengxing linked an issue Nov 6, 2024 that may be closed by this pull request

add_versions("v5.016", "66fc36f65033e5ec904481dd3d0df56500e90c0bfca23b2ae21b4a8d39e05ef1")
add_versions("v5.030", "b9e7e97257ca3825fcc75acbed792b03c3ec411d6808ad209d20917705407eac")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新版本 verilator 内部改了很多东西,对 VERILATOR_ROOT 的行为都变了,会 break 目前 xmake 内置的 verilator rules 。。要切到新版本,还得在 xmake 端做适配,估计要改很多的东西,还没空细看。。

建议先保留低版本

@@ -40,6 +36,7 @@ package("bison")
end)

on_install("@msys", function (package)
os.vrun("pacman -Sy --noconfirm --needed --disable-download-timeout bison")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

包配置里,不要直接调用 pacman/apt 等系统安装,会有权限问题,走 xmake 内置安装,而且你这么装,会装到系统路径,不是 包安装目录,会 break 掉 xrepo env

Copy link
Member

@waruqi waruqi Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

而 xmake 内部调用 pacman 会有对权限的很多处理,这里不能这么搞,如果源码安装不行,宁愿禁用这个平台

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是 msys2 包,用 add_deps 会加上 mingw 前缀导致安装失败

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/xmake-io/xmake/blob/d2c2baddcbccb4e305db563f6101ce6da47d3864/xmake/modules/package/manager/pacman/install_package.lua#L60
我发现 xmake 源码里选择下载名是 opt.pacman or name ,这个 opt.pacman 怎么用 add_deps 传进去

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是 msys2 包,用 add_deps 会加上 mingw 前缀导致安装失败

只要是用 pacman 安装的,这里统称为 pacman 包,如果有失败,可以根据实际错误 修下 install_package

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/xmake-io/xmake/blob/d2c2baddcbccb4e305db563f6101ce6da47d3864/xmake/modules/package/manager/pacman/install_package.lua#L60 我发现 xmake 源码里选择下载名是 opt.pacman or name ,这个 opt.pacman 怎么用 add_deps 传进去

我也忘记了加这个用来做什么的了。

packages/f/flex/xmake.lua Outdated Show resolved Hide resolved
@@ -36,7 +36,7 @@ package("bison")
end)

on_install("@msys", function (package)
os.vrun("pacman -Sy --noconfirm --needed --disable-download-timeout bison")
import("package.manager.pacman.install_package")("", {pacmna = "bison"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是这意思,整个 on_install 里都不要去调用 pacman ,走 add_deps("pacman::bison") 或者源码装不行么

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msys2 的 pacman 有多个仓库,flex/bison 这些在 msys2 仓库而不在 mingw64 仓库,走 add_deps("pacman::bison") 会判断 MSYSTEM 探测到是 mingw64 环境,然后加上前缀安装失败。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那也应该是改进 add_deps("pacman::bison") ,添加一个配置,让它能够区分源。 例如:
add_deps("pacman::bison", {configs = {msystem = "msys2"}})

通过 msystem 配置,手动指定包源,不走默认的 $MSYSTEM 不就好了么。

添加配置的方式,可以参考 conan 的

https://github.com/xmake-io/xmake/blob/dev/xmake/modules/package/manager/conan/configurations.lua

https://github.com/xmake-io/xmake/blob/1bae1746ea64f19e0fe7e24ec2b0bbf22e78dee4/xmake/modules/package/manager/conan/v2/install_package.lua#L316

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@star-hengxing star-hengxing requested a review from waruqi November 22, 2024 11:48
if is_subhost("msys") and package:is_library() then
local msys_dir = os.getenv("MINGW_PREFIX")
local header = path.join(path.directory(msys_dir), "usr/include/FlexLexer.h")
os.trycp(header, package:installdir("include"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种为啥会在 on_fetch 里面做,感觉有点 hack ,而且也没判断 opt.system ,不是应该在 on_install 里去 copy 到 installdir 么。

Copy link
Contributor Author

@star-hengxing star-hengxing Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msys subhost 下只能用 pacman 去安装 flex,那么有两种情况:

  1. 已经安装 flex,不会去执行 on_[load/install],那么就只能在 on_fetch hack 了。
  2. 如果没安装,那么让 xmake 去安装和拷贝。为什么这么拷贝,还是因为不能直接 add_includedirs /usr/include 的问题。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 如果已经安装了,为啥还要去 copy 呢,直接走 内置的 fetch 到的 includedirs 不就好了。。而且走的系统库,也不会去用 package installdir
  2. 如果没安装,走 on_install 里面去 copy 就好了,也不用走 on_fetch,等于重复 copy 了三次

另外,我是不建议这么搞,没法源码安装么

Copy link
Contributor Author

@star-hengxing star-hengxing Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果已经安装了,为啥还要去 copy 呢,直接走 内置的 fetch 到的 includedirs 不就好了。。而且走的系统库,也不会去用 package installdir

pacman::flex 这个系统包目前就是不能开箱即用,因为需要找个位置放 usr/include/FlexLexer.h ,那么放在 package:installdir("include") 自然最好,其他包构建如果需要就可以统一用 local includedir = flex:installdir("include")

如果没安装,走 on_install 里面去 copy 就好了,也不用走 on_fetch,等于重复 copy 了三次

on_fetch 是在调 pacman 安装之前,哪来的多次拷贝。

另外,我是不建议这么搞,没法源码安装么

msys 下的 flex 构建很麻烦,不会搞,所以走 pacman::flex 偷懒。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_fetch 是在调 pacman 安装之前,哪来的多次拷贝。

on_fetch 里面,你没区分判断 opt.system ,也就是一次 fetch ,就会触发两次 on_fetch 调用,先找 system,再找 xmake 路径包。

  • 安装之前,调用两次
  • 安装之后,会重新 fetch,调用两次

总共四次

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果没装 pacman::flex , 目前实现调用 pacman 安装后,会自动过滤 /usr/include 路径,所以肯定不会有 includedirs , 但会跳过 on_load/on_install 直接执行 on_test。

不会跳过,系统包,有自己的 on_install,另外 on_test 也不会执行才对。跟 package("flex")没任何关系,都是 add_deps pacman::flex 的系统包处理。

会自动过滤 /usr/include 路径很正常,之前做过处理,那就更没问题了。。按我上面说的 package("flex") on_install 里面处理下就行了,不可能不执行

除非在 on_install 去调用 pacman 安装,好像没啥办法了。

这个不会考虑,宁可不支持

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package("flex")
    if is_subhost("msys") then
        add_deps("pacman::flex", {private = true, configs = {msystem = "msys"}})
    end

    on_install("@msys", function (package)
        print("install flex")
    end)

试了下,没安装的时候,on_install 不是好好的呗调用了么,没啥问题,然后安安分分在 on_install 里面去 os.cp copy pacman::flex 安装到系统路径的 库和头文件到 package("flex"):installdir() 不就好了么。。pacman::flex 也没导出 /usr/include ,就更没问题了。。

$ xmake l scripts/test.lua -vD --shallow flex
{
  "flex"
}

C:\msys64\tmp\.xmake\241125\xmake-repo\test
add local repository(local-repo): D:\projects\personal\xmake-repo ok!
local repositories:
    local-repo D:\projects\personal\xmake-repo

global repositories:
    build-artifacts https://gitee.com/xmake-mirror/build-artifacts.git main
    xmake-repo https://gitee.com/tboox/xmake-repo.git master
    builtin-repo D:\projects\personal\xmake\xmake\repository

4 repositories were found!
checking for platform ... mingw
checking for architecture ... x86_64
checking for mingw directory ... C:/msys64/mingw64
configure
{
    ndk_stdcxx = true
    network = public
    host = windows
    clean = true
    proxy_pac = pac.lua
    mingw = C:/msys64/mingw64
    arch = x86_64
    theme = default
    ccache = true
    kind = static
    mode = release
    plat = mingw
    buildir = build
}
checking for git ... ok
git rev-parse HEAD
checking for gcc ... ok
checking for gzip ... ok
checking for tar ... ok
git rev-parse HEAD
finding flex from pacman ..
checking for pacman ... ok
checking for pacman::flex ... no
installing flex from pacman ..
pacman -Sy --noconfirm --needed --disable-download-timeout flex --verbose
Root      : /
Conf File : /etc/pacman.conf
DB Path   : /var/lib/pacman/
Cache Dirs: /var/cache/pacman/pkg/
Hook Dirs : /usr/share/libalpm/hooks/  /etc/pacman.d/hooks/
Lock File : /var/lib/pacman/db.lck
Log File  : /var/log/pacman.log
GPG Dir   : /etc/pacman.d/gnupg/
Targets   : flex
:: Synchronizing package databases...
 clangarm64                                                                                426.5 KiB   180 KiB/s 00:02 [#######################################################################] 100%
 mingw32                                                                                   204.6 KiB   124 KiB/s 00:02 [#######################################################################] 100%
 mingw64                                                                                   448.2 KiB   242 KiB/s 00:02 [#######################################################################] 100%
 ucrt64                                                                                    480.3 KiB   241 KiB/s 00:02 [#######################################################################] 100%
 clang32                                                                                    36.3 KiB  20.9 KiB/s 00:02 [#######################################################################] 100%
 clang64                                                                                   466.9 KiB   255 KiB/s 00:02 [#######################################################################] 100%
 msys                                                                                      309.9 KiB   706 KiB/s 00:00 [#######################################################################] 100%
resolving dependencies...
looking for conflicting packages...

Packages (2) m4-1.4.19-2  flex-2.6.4-3

Total Installed Size:  1.92 MiB

:: Proceed with installation? [Y/n]
(2/2) checking keys in keyring                                                                                         [#######################################################################] 100%
(2/2) checking package integrity                                                                                       [#######################################################################] 100%
(2/2) loading package files                                                                                            [#######################################################################] 100%
(2/2) checking for file conflicts                                                                                      [#######################################################################] 100%
(2/2) checking available disk space                                                                                    [#######################################################################] 100%
:: Processing package changes...
(1/2) installing m4                                                                                                    [#######################################################################] 100%
(2/2) installing flex                                                                                                  [#######################################################################] 100%
:: Running post-transaction hooks...
(1/1) Updating the info directory file...
finding flex from pacman ..
checking for pacman::flex ... flex 2.6.4
{
  libfiles = {
    "/usr/lib/libfl.a"
  },
  static = true,
  version = "2.6.4",
  links = {
    "fl"
  },
  linkdirs = {
    "/usr/lib"
  }
}

  => install pacman::flex latest .. ok
install flex <--------------------------------------------------------- on_install
checking for flex ... no
checking for win_flex ... no
checking for flex ... no
{
  envs = {
    PATH = {
      "bin"
    }
  },
  license = "BSD-2-Clause",
  deps = { },
  artifacts = {
    installdir = "C:\Users\wangrunqing\AppData\Local\.xmake\packages\f\flex\2.6.4\b850a8b09fa7422f90d514607a6cc63f"
  },
  kind = "binary",
  repo = {
    url = "D:\projects\personal\xmake-repo",
    name = "local-repo",
    commit = "440e0cd27b2c5c0503f552b996aea53b7d43d094"
  },
  plat = "msys",
  pathenvs = {
    "ACLOCAL_PATH",
    "DYLD_LIBRARY_PATH",
    "LD_LIBRARY_PATH",
    "PKG_CONFIG_PATH",
    "CMAKE_PREFIX_PATH",
    "PYTHONPATH",
    "PATH"
  },
  name = "flex",
  version = "2.6.4",
  configs = {
    shared = false,
    pic = true,
    debug = false
  },
  librarydeps = { },
  arch = "x86_64",
  mode = "release"
}

flex -h
Usage: flex [OPTIONS] [FILE]...
Generates programs that perform pattern-matching on text.

Table Compression:
  -Ca, --align      trade off larger tables for better memory alignment
  -Ce, --ecs        construct equivalence classes
  -Cf               do not compress tables; use -f representation
  -CF               do not compress tables; use -F representation
  -Cm, --meta-ecs   construct meta-equivalence classes
  -Cr, --read       use read() instead of stdio for scanner input
  -f, --full        generate fast, large scanner. Same as -Cfr
  -F, --fast        use alternate table representation. Same as -CFr
  -Cem              default compression (same as --ecs --meta-ecs)

Debugging:
  -d, --debug             enable debug mode in scanner
  -b, --backup            write backing-up information to lex.backup
  -p, --perf-report       write performance report to stderr
  -s, --nodefault         suppress default rule to ECHO unmatched text
  -T, --trace             flex should run in trace mode
  -w, --nowarn            do not generate warnings
  -v, --verbose           write summary of scanner statistics to stdout
      --hex               use hexadecimal numbers instead of octal in debug outputs

Files:
  -o, --outfile=FILE      specify output filename
  -S, --skel=FILE         specify skeleton file
  -t, --stdout            write scanner on stdout instead of lex.yy.c
      --yyclass=NAME      name of C++ class
      --header-file=FILE   create a C header file in addition to the scanner
      --tables-file[=FILE] write tables to FILE

Scanner behavior:
  -7, --7bit              generate 7-bit scanner
  -8, --8bit              generate 8-bit scanner
  -B, --batch             generate batch scanner (opposite of -I)
  -i, --case-insensitive  ignore case in patterns
  -l, --lex-compat        maximal compatibility with original lex
  -X, --posix-compat      maximal compatibility with POSIX lex
  -I, --interactive       generate interactive scanner (opposite of -B)
      --yylineno          track line count in yylineno

Generated code:
  -+,  --c++               generate C++ scanner class
  -Dmacro[=defn]           #define macro defn  (default defn is '1')
  -L,  --noline            suppress #line directives in scanner
  -P,  --prefix=STRING     use STRING as prefix instead of "yy"
  -R,  --reentrant         generate a reentrant C scanner
       --bison-bridge      scanner for bison pure parser.
       --bison-locations   include yylloc support.
       --stdinit           initialize yyin/yyout to stdin/stdout
       --nounistd          do not include <unistd.h>
       --noFUNCTION        do not generate a particular FUNCTION

Miscellaneous:
  -c                      do-nothing POSIX option
  -n                      do-nothing POSIX option
  -?
  -h, --help              produce this help message
  -V, --version           report flex version
  => install flex 2.6.4 .. ok

Copy link
Contributor Author

@star-hengxing star-hengxing Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像终于找到问题所在。
如果用户没装 pacman::flex ,没问题。
如果已经装了,目前 xmake::flex 会自己 fetch 到 pacman::flex ,即使加了 deps ,所以没执行 on_install 去 copy ,除非用 add_requires("flex", {kind = "library", system = false})

$ xmake f -c -v -y
checking for platform ... mingw
checking for architecture ... x86_64
checking for mingw directory ... C:/msys64/mingw64
checking for git ... ok
checking for gzip ... ok
checking for tar ... ok
git rev-parse HEAD
checking for gcc ... ok
checking for pacman ... ok
checking for pacman::flex ... flex 2.6.4
checking for xmake::flex ... no
checking for emerge ... no
checking for pkg-config ... ok
checking for flex ... pacman::flex 2.6.4
$ xmake
[ 50%]: cache compiling.release src\main.cpp
error: src\main.cpp:2:10: fatal error: FlexLexer.h: No such file or directory
    2 | #include <FlexLexer.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
  > in src\main.cpp

Copy link
Member

@waruqi waruqi Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那是因为设置成了 binary,安装好 pacman::flex 后,它已经在 usr/bin 下了,安装 flex 时候,尝试 fetch 探测 Flex 命令存在,就默认用系统的了。。这也没啥问题哈,因为是作为 binary 装的 flex 不是库,能有直接用的 binary 当然直接运行了。

关键是为啥会默认作为 binary kind 呢

就算里面有 tools,按理也是默认 library, 然后加 bin path .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没考虑周到吧,只能根据需求迭代。

@star-hengxing star-hengxing requested a review from waruqi December 13, 2024 12:44
@waruqi waruqi merged commit 7f0e347 into dev Dec 13, 2024
67 checks passed
@waruqi waruqi deleted the verilator-cmake branch December 13, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants