When generating Go code, make -cgo the default.

Add new -no-cgo option to disable the default.
Keep -cgo as a no-op for existing users.
This commit is contained in:
Ian Lance Taylor 2019-04-19 12:49:56 -07:00
commit 77f075b6e8
3 changed files with 38 additions and 29 deletions

View file

@ -125,16 +125,15 @@ Go distribution. To generate code for gccgo, you should also use the
</p>
<p>
When using the <tt>-cgo</tt> option, SWIG will generate files that can be used
directly by <tt>go build</tt>. Starting with the Go 1.5 distribution the
<tt>-cgo</tt> option has to be given. Put your SWIG interface file in a
directory under GOPATH/src, and give it a name that does <b>not</b> end in the
.swig or .swigcxx extension. Typically the SWIG interface file extension is .i
in this case.
By default SWIG will generate files that can be used directly
by <tt>go build</tt>. This requires Go 1.2 or later. Put your SWIG
interface file in a directory under GOPATH/src, and give it a name
that does <b>not</b> end in the .swig or .swigcxx extension.
Typically the SWIG interface file extension is .i in this case.
</p>
<div class="code"><pre>
% swig -go -cgo example.i
% swig -go example.i
% go install
</pre></div>
@ -144,15 +143,16 @@ usual.
</p>
<p>
To use SWIG without the <tt>-cgo</tt> option, more steps are required. Recall
that this only works with Go versions before 1.5. When using Go version 1.2 or
later, or when using gccgo, the code generated by SWIG can be linked directly
into the Go program. A typical command sequence when using the Go compiler of
the Go distribution would look like this:
SWIG can be used without cgo, via the <tt>-no-cgo</tt> option, but
more steps are required. This only works with Go versions before 1.5.
When using Go version 1.2 or later, or when using gccgo, the code
generated by SWIG can be linked directly into the Go program. A
typical command sequence when using the Go compiler of the Go
distribution would look like this:
</p>
<div class="code"><pre>
% swig -go example.i
% swig -go -no-cgo example.i
% gcc -c code.c # The C library being wrapped.
% gcc -c example_wrap.c
% go tool 6g example.go
@ -169,7 +169,7 @@ sequence for this approach would look like this:
</p>
<div class="code"><pre>
% swig -go -use-shlib example.i
% swig -go -no-cgo -use-shlib example.i
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
@ -200,10 +200,15 @@ swig -go -help
<tr>
<td>-cgo</td>
<td>Generate files to be used as input for the Go cgo tool. This
option is required for Go 1.5 and later, and works for Go 1.2 and
later. In the future this option will likely become the
default.</td>
<td>Generate files to be used as input for the Go cgo tool. This is
the default.</td>
</tr>
<tr>
<td>-no-cgo</td>
<td>Generate files that can be used directly, rather than via the Go
cgo tool. This option does not work with Go 1.5 or later. It is
required for versions of Go before 1.2.</td>
</tr>
<tr>
@ -268,11 +273,11 @@ swig -go -help
<p>There are two different approaches to generating wrapper files,
controlled by SWIG's <tt>-cgo</tt> option. The <tt>-cgo</tt> option
works with Go version 1.2 or later. It is required when using Go
version 1.5 or later.</p>
controlled by SWIG's <tt>-no-cgo</tt> option. The <tt>-no-cgo</tt>
option only works with version of Go before 1.5. It is required
when using versions of Go before 1.2.</p>
<p>With or without the <tt>-cgo</tt> option, SWIG will generate the
<p>With or without the <tt>-no-cgo</tt> option, SWIG will generate the
following files when generating wrapper code:</p>
<ul>
@ -296,8 +301,8 @@ or C++ compiler.
</li>
</ul>
<p>When neither the <tt>-cgo</tt> nor the <tt>-gccgo</tt> option is
used, SWIG will also generate an additional file:</p>
<p>When the <tt>-no-cgo</tt> option is used, and the <tt>-gccgo</tt>
option is not used, SWIG will also generate an additional file:</p>
<ul>
<li>