Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 1 | Some notes on development of the Go frontend |
| 2 | Ian Lance Taylor |
| 3 | iant@golang.org |
| 4 | |
| 5 | The Go frontend currently only works with GCC. I want to make it more |
| 6 | portable, but that work is not complete. |
| 7 | |
| 8 | |
| 9 | Go frontend as part of GCC |
| 10 | -------------------------- |
| 11 | |
| 12 | There is a copy of the Go frontend in the GCC source code. However, |
| 13 | the Go frontend source code repository is not the GCC source code |
| 14 | repository. This means that if you want to modify the Go frontend, |
| 15 | you need to do some setup. This is how I do it. |
| 16 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 17 | The Go frontend sources are stored using Git hosted at |
| 18 | go.googlesource.com, and mirrored on github.com. To check out the |
| 19 | source code: |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 20 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 21 | git clone https://go.googlesource.com/gofrontend |
| 22 | |
Tobias Klauser | 43f83e9 | 2020-06-25 16:56:24 +0200 | [diff] [blame] | 23 | (or use the mirror on github: git clone https://github.com/golang/gofrontend) |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 24 | |
| 25 | That gives you the frontend only. Now you need a copy of the GCC |
Tobias Klauser | 43f83e9 | 2020-06-25 16:56:24 +0200 | [diff] [blame] | 26 | source code. See https://gcc.gnu.org/git.html for details, or simply: |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 27 | |
Tobias Klauser | d65e5a2 | 2020-06-15 13:36:49 +0200 | [diff] [blame] | 28 | git clone git://gcc.gnu.org/git/gcc |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 29 | |
| 30 | The GCC source code will have a copy of the Go frontend, but because |
| 31 | you want to change the Go frontend, you will need to replace that copy |
| 32 | with your own. I do this using symlinks. Symlinking the Go frontend |
| 33 | proper is trivial. Symlinking libgo is a bit harder, because |
| 34 | convenient use of automake and autoconf requires that they be able to |
| 35 | see the sources in top level of the GCC repository. So this is what I |
| 36 | do: |
| 37 | |
| 38 | rm -rf gcc/go/gofrontend |
| 39 | ln -s GOFRONTEND/go gcc/go/gofrontend |
| 40 | rm -rf libgo |
Ian Lance Taylor | d3b961d | 2014-01-08 13:58:47 -0800 | [diff] [blame] | 41 | mkdir libgo |
| 42 | for f in GOFRONTEND/libgo/*; do ln -s $f libgo/`basename $f`; done |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 43 | |
| 44 | You can then build GCC as usual, with --enable-languages=go. The |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 45 | build will use the Go frontend in your Git repository. |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 46 | |
| 47 | This is all you need to build gccgo yourself and develop your own |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 48 | patches. To get your patch committed, send them in using "git |
| 49 | codereview mail" as described at |
Tobias Klauser | 43f83e9 | 2020-06-25 16:56:24 +0200 | [diff] [blame] | 50 | https://golang.org/doc/gccgo_contribute.html ; it's the same process as |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 51 | changes for the regular Go repository. |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 52 | |
| 53 | At present I am the only person who commits changes to the Go frontend |
| 54 | repository. Because the GCC repository has a copy of the Go frontend, |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 55 | I need to commit changes to both repositories. To do this, I use a |
| 56 | script that copies changes from the Git repository to GCC's SVN |
| 57 | repository. This script uses a file MERGE that exists only in the GCC |
| 58 | repository. This is the script: |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 59 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 60 | ================================================== |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 61 | #!/bin/sh |
| 62 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 63 | set -e |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 64 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 65 | merge="/home/iant/gcc/trunk/gcc/go/gofrontend/MERGE" |
| 66 | current=`head -1 $merge` |
| 67 | next=`git log ${current}.. | grep '^commit' | tail -1 | sed -e 's/^[^ ]* //'` |
| 68 | |
| 69 | if test "$next" = ""; then |
| 70 | echo "gosync: already up to date" |
| 71 | exit 0 |
| 72 | fi |
| 73 | |
| 74 | if git show -p $next | grep -e '^\(---\|+++\)' | fgrep 'go/'; then |
| 75 | git log -1 $next > /home/iant/gcc/trunk/svn-commit.tmp |
| 76 | git show -p $next | \ |
| 77 | sed -e 's|\(^[-+][-+][-+] [ab]\)/go|\1/gcc/go/gofrontend|' | \ |
| 78 | (cd /home/iant/gcc/trunk && patch -p1) |
| 79 | else |
| 80 | echo "gosync: no relevant files in change $next" |
| 81 | fi |
| 82 | |
| 83 | (echo ${next}; sed -ne '2,$p' $merge) > ${merge}.tmp |
| 84 | mv ${merge}.tmp ${merge} |
| 85 | ================================================== |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 86 | |
| 87 | (When I'm working with a GCC release branch, I have variants which do |
| 88 | the same thing with my copy of the GCC release branch.) |
| 89 | |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 90 | Now every time I submit a change to the gofrontend repository, I run |
| 91 | gosync to copy the change to my copy of the GCC repository, and the |
| 92 | commit message is stored in svn-commit.tmp in the GCC repository. I |
| 93 | don't automatically commit to both git and svn at once because some |
| 94 | gofrontend changes require changes to other parts of GCC, and an |
| 95 | automatic commit to GCC would mean that GCC was temporarily broken. |
| 96 | So instead after pushing the submit button on |
| 97 | go-review.googlesource.com I run "gosync; svn commit". GCC rules |
| 98 | require that all GCC patches be sent to the mailing list |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 99 | gcc-patches@gcc.gnu.org with an explanation, so I do that as well when |
| 100 | I run "svn commit". |
| 101 | |
| 102 | In summary, there are three steps to every change to the gofrontend: |
Ian Lance Taylor | 8eeba3a | 2015-06-15 10:52:49 -0700 | [diff] [blame] | 103 | 1) git submit |
Ian Lance Taylor | 6b1ed1f | 2013-06-20 13:21:55 -0700 | [diff] [blame] | 104 | 2) svn commit |
| 105 | 3) send e-mail to gcc-patches@gcc.gnu.org |
| 106 | |
| 107 | For the convenience of people who want to use gccgo without waiting |
| 108 | for a release and without living on tip, I maintain a gccgo branch of |
Baokun Lee | 713c461 | 2019-02-22 18:55:36 +0800 | [diff] [blame] | 109 | GCC. This lives at svn://gcc.gnu.org/svn/gcc/branches/gccgo. I maintain |
| 110 | it using the general GCC branch policies described at |
Tobias Klauser | 43f83e9 | 2020-06-25 16:56:24 +0200 | [diff] [blame] | 111 | https://gcc.gnu.org/wiki/SvnBranch . |