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

feat: support llpkg for building #1048

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open

Conversation

MeteorsLiu
Copy link
Member

@MeteorsLiu MeteorsLiu commented Apr 1, 2025

Resolve #1058

Build process of llpkg:

  1. check it's llpkg by parsing llpkg.cfg
  2. install it by ghReleaseInstaller
  3. set PKG_CONFIG_PATH to LLGoCacheDir/{{ModulePath}}

@MeteorsLiu MeteorsLiu changed the title feat: support llpkg for building feat: support llpkg for building Apr 1, 2025
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

Attention: Patch coverage is 45.45455% with 270 lines in your changes missing coverage. Please review.

Project coverage is 86.18%. Comparing base (a7c23e2) to head (04f0096).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...nternal/installer/githubreleases/githubreleases.go 32.97% 103 Missing and 23 partials ⚠️
compiler/internal/mod/mod.go 22.58% 48 Missing ⚠️
compiler/internal/mod/cache.go 70.64% 22 Missing and 10 partials ⚠️
compiler/internal/modget/get.go 0.00% 20 Missing ⚠️
compiler/internal/installer/config/parse.go 0.00% 14 Missing ⚠️
compiler/internal/env/env.go 0.00% 9 Missing ⚠️
compiler/internal/mod/metadata.go 82.69% 6 Missing and 3 partials ⚠️
compiler/internal/pc/env.go 0.00% 8 Missing ⚠️
compiler/internal/mod/version.go 87.87% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1048      +/-   ##
==========================================
- Coverage   89.07%   86.18%   -2.90%     
==========================================
  Files          27       35       +8     
  Lines        6959     7454     +495     
==========================================
+ Hits         6199     6424     +225     
- Misses        720      953     +233     
- Partials       40       77      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -302,6 +378,10 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs
continue
}
built[pkg.ID] = none{}

err := buildLLPkg(ctx, pkg, verbose)
Copy link
Member

Choose a reason for hiding this comment

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

不要按 pkg 来查找,而是按 module 检查,参考 allPkgs 函数中可以获取所有使用的 module 。

Copy link
Member Author

@MeteorsLiu MeteorsLiu Apr 2, 2025

Choose a reason for hiding this comment

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

老师我没太明白,意思是先从allPkgs获取所有module,然后安装,最后再build吗?
还是说,像allPkgs一样,Visit所有package途中,一个个去安装?

Copy link
Member Author

@MeteorsLiu MeteorsLiu Apr 2, 2025

Choose a reason for hiding this comment

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

}

func getModule(ctx *context, ver module.Version, llpkg installer.Package, verbose bool) error {
cmd := exec.Command("llgo", "get", ver.String())
Copy link
Member

Choose a reason for hiding this comment

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

通常情况下,module 已经存在,不需要重新 get 。

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -281,6 +300,49 @@ type context struct {

needRt map[*packages.Package]bool
needPyInit map[*packages.Package]bool

installer installer.Installer
moduleVersion map[string]*module.Version
Copy link
Member

@visualfc visualfc Apr 2, 2025

Choose a reason for hiding this comment

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

查找的动态库对应的是 mod ,而不是 pkgpath 。可以将 mod 的 path@version 或 module.Version 作为 key,并且 modpath 必须为以github.com/goplus/llpkg 开始。

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -281,6 +300,49 @@ type context struct {

needRt map[*packages.Package]bool
needPyInit map[*packages.Package]bool

mod map[string]*module.Version
Copy link
Member

Choose a reason for hiding this comment

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

llpkgMod map[module.Version]none

Copy link
Member Author

@MeteorsLiu MeteorsLiu Apr 2, 2025

Choose a reason for hiding this comment

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

老师,我发现这套根据module来的方案有个问题。
因为Go允许同库不同版本,只需要加个module path后缀就行,例如
github.com/goplus/llpkg/zlib/v2

那么,根据之前根据module设置PC似乎并不对,例如说A库依赖zlib 1.3.1 => v2.0.0, B库依赖zlib 1.2.1 => v1.0.0
那么,如果说某个package先依赖了A,后依赖B,那么zlib 1.3.1的PC总是比zlib 1.2.1优先级要高,因此我还是决定将根据package来设置pc,而llpkg拉取则是在Visit途中完成

fix: set pc by each package

Copy link
Member Author

Choose a reason for hiding this comment

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

老师我发现以上依然无法解决问题,不过按照package设置pc还是需要的,因为map循环是乱序的,pc需要顺序

return filepath.Join(dir, "lib", "pkgconfig"), nil
}

func buildAllLLPkg(ctx *context, verbose bool) {
Copy link
Member

Choose a reason for hiding this comment

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

函数名称不准确

Copy link
Member Author

Choose a reason for hiding this comment

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

installer installer.Installer
}

func getModule(ctx *context, ver module.Version, llpkg installer.Package, verbose bool) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

函数名称不准确

Copy link
Member Author

Choose a reason for hiding this comment

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

return "", err
}

_, err = os.Stat(dir)
Copy link
Member

Choose a reason for hiding this comment

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

如果建立目录完成,但安装未成功,下次则认为已经存在。可以判断是否存在 dir/lib/pkgconfig 。

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -302,6 +347,9 @@ func buildAllPkgs(ctx *context, initial []*packages.Package, verbose bool) (pkgs
continue
}
built[pkg.ID] = none{}

setDepsPC(ctx, pkg)
Copy link
Member

Choose a reason for hiding this comment

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

只有以 github.com/goplus/llpkg/ 开始的 pkg 才需要设置 llpkg 的 pc 。

Copy link
Member Author

Choose a reason for hiding this comment

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

}
}
if len(pcDir) > 0 {
os.Setenv("PKG_CONFIG_PATH", pc.AppendPCPath(strings.Join(pcDir, ":")))
Copy link
Member

Choose a reason for hiding this comment

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

很难理解 pc.AppendPCPath 做了什么,建议去掉 pc 这个 pkg 。

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

qiniu-x bot commented Apr 3, 2025

[Git-flow] Hi @MeteorsLiu, There are some suggestions for your information:


Rebase suggestions

  • Following commits have duplicated messages

    revert

    revert

    fix: remove log

    fix: remove log

Which seems insignificant, recommend to use git rebase command to reorganize your PR.

For other git-flow instructions, recommend refer to these examples.

If you have any questions about this comment, feel free to raise an issue here:

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.

Support building llpkg
3 participants