加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Go1.7将支持二进制包分发

发布时间:2020-12-16 18:32:02 所属栏目:大数据 来源:网络整理
导读:Go1.7将支持二进制包分发 不出意外的话,Go1.7将在8月份发布。Go1.7最大的变化是引入SSA优化技术,号称有 -10% 到 30~40?% 的性能提升。 对于Windows用户,还有一个迟来的特性:就是生成C静态库(补充: Go1.7已经可生成静态库),然后可以用gcc工具将这个C静态

Go1.7将支持二进制包分发

不出意外的话,Go1.7将在8月份发布。Go1.7最大的变化是引入SSA优化技术,号称有-10%30~40?%的性能提升。

对于Windows用户,还有一个迟来的特性:就是生成C静态库(补充: Go1.7已经可生成静态库),然后可以用gcc工具将这个C静态库再打包为dll。 直接生成C接口的dll特性暂时还不确定能否完成。

不过我们这里主要关注另一个新特性:就是以二进制方式分发Go包。

为了保密源代码,已经出现了各种nb的技术,二进制发布虽然只是比较低级的一种方式, 但是总比没有好。

先看看相关的文档:

// Binary-Only Packages
//
// It is possible to distribute packages in binary form without including the
// source code used for compiling the package. To do this,the package must
// be distributed with a source file not excluded by build constraints and
// containing a "//go:binary-only-package" comment.
// Like a build constraint,this comment must appear near the top of the file,// preceded only by blank lines and other line comments and with a blank line
// following the comment,to separate it from the package documentation.
// Unlike build constraints,this comment is only recognized in non-test
// Go source files.
//
// The minimal source code for a binary-only package is therefore:
//
//	//go:binary-only-package
//
//	package mypkg
//
// The source code may include additional Go code. That code is never compiled
// but will be processed by tools like godoc and might be useful as end-user
// documentation.
//

简单来说就是先将pkg打包为.a文件,然后放入$GOPATH/pkg目录的相应位置, 然后在$GOPATH/src相应目录放入一个空的Go源文件,里面加入以下注释:

//go:binary-only-package

然后在 go build 的时候就会跳过重现编译代码的步骤,直接使用.a文件了(.a文件里面含有导入信息)。 当然,包的声明语句 package mypkg 还要保留。

在以二进制方式发布时,对应源文件中还是建议保留包的文档信息(不会build而已),这样便于用go doc查阅包文档。

实际中,很多模块都有很多pkg组成,手工每个依赖的pkg会很麻烦, 估计需要一个专门的二进制包分发工具。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读