Do people compile their own version of the Go compiler?

agolangf · · 479 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m curious if anyone compiles their own version of the Go compiler, and what the process is like, how well-commented the Go compiler is, how easy it is to get it to compile, and so forth. I mean, is it as easy as compiling any other project?</p> <p>I ask this because it seems like something that should be pretty simple, given that Go is self-hosting (written in Go), and usually large Go codebases are highly readable and pretty &#34;standard&#34;. So it could be a source of inspiration as well as best practices, and seems like something that would be &#34;easy&#34; to compile. And maybe it&#39;s very, very well-commented.</p> <p>Thanks for any information :)</p> <hr/>**评论:**<br/><br/>dlsniper: <pre><blockquote> <p>I&#39;m curious if anyone compiles their own version of the Go compiler</p> </blockquote> <p>Yes (I don&#39;t because I don&#39;t like wasting time to do something that&#39;s already done)</p> <blockquote> <p>what the process is like</p> </blockquote> <p><a href="https://golang.org/doc/install/source" rel="nofollow">https://golang.org/doc/install/source</a></p></pre>throwawaybeginr: <pre><p>How much time are we talking about to follow that document? (Glancing over it, I can guess anywhere from &#34;90 seconds&#34; to &#34;never - you will probably not succeed if you haven&#39;t done this before.&#34; I&#39;m just a beginner.) In addition, how long does the build process itself take?</p></pre>JHunz: <pre><p>It is neither that difficult, nor that time-consuming (especially after the first time). I compile from source whenever I upgrade Go. You do have to run make once for each architecture you intend to be able to compile on that machine, so if you want to cross-compile to all of them it&#39;s quite a bit slower than just doing amd64 or whatever. I think I remember each execution of make taking 5-ish minutes, but I&#39;m usually tabbed off doing something else so I don&#39;t keep careful track.</p></pre>dchapes: <pre><blockquote> <p>You do have to run make once for each architecture you intend to be able to compile on</p> </blockquote> <p>I haven&#39;t had to do that for ages. I don&#39;t recall what Go version changed that but now I just run <code>bash all.bash</code> once and then run <code>env GOOS=xxx GOARCH=yyy go install std</code> for each combination of GOOS and GOARCH I care about (actually, for kicks I run <code>go tool dist list | awk -F / &#39;{print &#34;env GOOS=&#34;$1 &#34; GOARCH=&#34; $2 &#34; go install std&#34;}&#39; | sh -x</code> to build them all).</p></pre>JHunz: <pre><p>Oh, that&#39;s nice</p></pre>cks: <pre><p>If you&#39;re only going to cross-compile things occasionally, I&#39;ve had good experiences with not doing the <code>go install std</code> before hand and just doing <code>GOARCH=... go build ...</code> when I want to cross-compile something in specific. I assume that this is less efficient than pre-building the standard library, but since I only cross-compile occasionally and I rebuild Go frequently, it saves me time overall.</p></pre>cks: <pre><p>Building Go from source is both easy and fast. You can find various &#39;how to do it&#39; instructions on the web; <a href="https://utcc.utoronto.ca/%7Ecks/space/blog/programming/GoBuildFromSource" rel="nofollow">here is mine</a>. Just building Go itself is pretty fast (about 30 seconds on a vintage-2011 desktop for me), but you can and probably should also run the self-tests, which will add a minute or two. It&#39;s certainly fast enough that you can rebuild casually. Once built, you can use your new Go simply by making sure that its version of the various binaries are first in your $PATH.</p> <p>How many useful comments there are in the compiler, the runtime, and the standard packages vary somewhat. I find it pretty easy to read more straightforward sections of the standard packages (and it can be both interesting and useful), but getting down in the depths of the runtime and the compiler can require some work to understand the code.</p></pre>LogicX: <pre><p>Yes, on mac using <a href="https://github.com/moovweb/gvm" rel="nofollow">https://github.com/moovweb/gvm</a></p></pre>dim13: <pre><p>Yes, I maintain my own version of OpenBSD port. Background: official one lags a bit behind.</p></pre>tv64738: <pre><p>I don&#39;t see how readability has anything to do with building the compiler locally.</p> <p>And yes, I build lots of Go compilers locally.</p> <pre><code>$ ls -d src/go{,-*} src/go/ src/go-1.5/ src/go-1.6/ src/go-1.7/ src/go-1.8/ </code></pre></pre>throwawaybeginr: <pre><p>The questions are completely orthogonal. :)</p></pre>mcouturier: <pre><p>Use the official &#34;contributing to go&#34; document and start at the git clone part.</p> <p>Pretty easy actually.</p></pre>jussij: <pre><p>I&#39;m on the Windows 10 platform and I install the Go compiler from source. It is a very easy process.</p> <p>These are the steps:</p> <ul> <li>Download and install the bootstrap compiler (you only do this once)</li> <li>Set the <strong>GOROOT_BOOTSTRAP</strong> environment variable to that bootstrap install folder (you only do this once)</li> <li>Download the Go source code</li> <li>Run the build using the <code>C:\Go\src\all.bat</code></li> </ul> <p>So basically once you have done it once it is just a two step process.</p></pre>throwawaybeginr: <pre><p>thanks - just what I wanted to know.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

479 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传