-
Notifications
You must be signed in to change notification settings - Fork 10
feat: support for golang #476
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20f8432
feat: initial jsii-srcmak work for golang
campionfellin 162a8e0
feat: continue jsii-srcmak work for golang
ansgarm 80ad275
chore: add test and update snapshots for golang
ansgarm 8544a10
chore: use const instead of let
ansgarm 1603ba4
docs: document Golang in Readme
ansgarm f3970b7
feat: update Go support to use source code without go.mod file
ansgarm 91fb3e7
feat: don't assume a license for the generated code
ansgarm a958f91
chore: improve docs about generating go code into subdirectories
ansgarm 06781b5
Merge branch 'main' into campionfellin/golang
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,45 @@ original module. This code depends on the following NuGet package (It is already | |
|
|
||
| The output directory will also include a tarball `[email protected]` that must be bundled in your project (It is already included as an embedded resource in the generated project). | ||
|
|
||
| ### Go Output | ||
|
|
||
| To produce a Go module from your source, use the `golang` option: | ||
|
|
||
| ```ts | ||
| await srcmak('srcdir', { | ||
| golang: { | ||
| outdir: '/path/to/project/root', | ||
| moduleName: 'github.com/yourorg/your-root-project', | ||
| packageName: 'helloworld' | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| Or the `--golang-*` switches in the CLI: | ||
|
|
||
| ```bash | ||
| $ jsii-srcmak /src/dir --golang-outdir=dir --golang-module="github.com/yourorg/your-root-project" --golang-package="helloworld" | ||
| ``` | ||
|
|
||
| * The `outdir`/`--golang-outdir` option points to the root directory of your base Go project (where your `go.mod` is in, if you have one). | ||
| * The `moduleName`/`--golang-module` option must match the Go module name of the project that includes the generated source code e.g. `github.com/yourorg/your-root-project`. This is currently required, because the generated code needs to reference a submodule which is generated in a nested directory (see also upstream issue https://github.com/aws/jsii/issues/2847 for more information). | ||
| * The `packageName`/`--golang-package` is the package in which the generated Go code will be in. It will be placed in the submodule. So the import path becomes e.g. `github.com/yourorg/your-root-project/yourpackage`. | ||
|
|
||
| The output directory will include a directory named with the `packageName`/`--golang-package` containing the generated Go code. | ||
| This code depends on the following Go module: | ||
|
|
||
| - [jsii-runtime-go](github.com/aws/jsii-runtime-go) | ||
|
|
||
| which you need to include in your `go.mod`: | ||
| ``` | ||
| require github.com/aws/jsii-runtime-go v1.29.0 # update the version to match the jsii version used in your version of jsii-srcmak | ||
| ``` | ||
|
|
||
|
|
||
| #### Nested output directories | ||
| It is possible to set the `outdir`/`--golang-outdir` option to a directory other than the root of your base Go project. For example, if you want to nest the generated code in a folder `generated` or similar. | ||
| In that case you need to append the subdirectory to the module name (e.g. `github.com/yourorg/your-root-project/generated`). Your import path will then become e.g. `github.com/yourorg/your-root-project/generated/yourpackage`. | ||
|
|
||
| ### Entrypoint | ||
|
|
||
| The `entrypoint` option can be used to customize the name of the typescript entrypoint (default is `index.ts`). | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,13 @@ export interface Options { | |
| * @default - C# is not generated | ||
| */ | ||
| csharp?: CSharpOutputOptions; | ||
|
|
||
| /** | ||
| * Produces Golang code. | ||
| * | ||
| * @default - go is not generated | ||
| */ | ||
| golang?: GoLangOutputOptions; | ||
| } | ||
|
|
||
| export interface JsiiOutputOptions { | ||
|
|
@@ -99,3 +106,29 @@ export interface CSharpOutputOptions { | |
| */ | ||
| namespace: string; | ||
| } | ||
|
|
||
| export interface GoLangOutputOptions { | ||
| /** | ||
| * Base root directory. | ||
|
||
| */ | ||
| outdir: string; | ||
|
|
||
| /** | ||
| * The go module name | ||
| * | ||
| * This must match the name of the parent go module the source code is generated in (e.g. github.com/yourorg/yourproject). | ||
| * See https://github.com/aws/jsii/issues/2847#issue-896419111 for the background on why this is required. | ||
| * | ||
| * This must follow standard Go module name conventions. | ||
| * For example, it cannot include an underscore ('_') or be camelCased | ||
| */ | ||
| moduleName: string; | ||
|
|
||
| /** | ||
| * The name of the Go package. | ||
| * | ||
| * E.g. "tools" would result in something like github.com/yourorg/yourproject/tools | ||
| * depeding on the supplied moduleName | ||
| */ | ||
| packageName: string; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.