Skip to content
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

Golang Wrap Support #1074

Merged
merged 77 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
89219f1
codegen for wasm-go
ramilexe Jul 25, 2022
e58ad84
for debug only
ramilexe Aug 3, 2022
e324498
Add serialization and deserialization for common types
n0cte Aug 16, 2022
5ad800a
debug: parse template filename
ramilexe Aug 16, 2022
bbf6f57
add serialization and deserialization for impors, interfaces, modules
n0cte Aug 18, 2022
7e99c54
prettify generated golang code
n0cte Aug 22, 2022
bfafa77
fix property name for args
n0cte Aug 22, 2022
d31f21e
fix schema output structure
n0cte Aug 23, 2022
30f5a34
fix code style
n0cte Aug 23, 2022
99a31ac
don't filter for wasm-go codegen
ramilexe Aug 23, 2022
6d637e4
fix tests regarding latest changes from origin
ramilexe Aug 23, 2022
a34daeb
add golang package injection
n0cte Aug 24, 2022
97bf3aa
Merge pull request #1180 from n0cte/go-codegen-inject-module
ramilexe Aug 24, 2022
91ce0a8
remove debug
ramilexe Aug 23, 2022
e2506a8
add compiler options override for Golang
ramilexe Aug 24, 2022
b29151f
add compiler options override for Golang
ramilexe Aug 24, 2022
81dae40
fix build for rust
ramilexe Aug 24, 2022
2586cc4
move env variable to desired section
n0cte Aug 24, 2022
43755c7
allow go-package allocation in imports
n0cte Aug 24, 2022
a3f8847
custom types must be capitalized
n0cte Aug 24, 2022
095377b
add mustache fn for checking scalar prefix
n0cte Aug 24, 2022
cf49e7b
split the module into two packages
n0cte Aug 24, 2022
7b07dc1
fix code linting
n0cte Aug 24, 2022
14d0e0a
Merge pull request #1182 from n0cte/go-codegen-fix-env
ramilexe Aug 24, 2022
d9f7b29
parse go.mod file
ramilexe Aug 25, 2022
6bf4b44
dockerfile for golang build
ramilexe Aug 25, 2022
bca807f
fix golang code generated
ramilexe Aug 26, 2022
2ae2c81
Golang: add test cases (#1198)
n0cte Sep 6, 2022
9c5b9d3
simplify package url matching (#1184)
n0cte Sep 6, 2022
b39fcef
fix logic of function toWasmMap (#1214)
n0cte Sep 6, 2022
2cf84db
chore: update with latest
cbrzn Apr 17, 2023
ba2335d
chore: first iteration of build strategies with golang + add tood
cbrzn Apr 24, 2023
5ba196f
Merge branch 'origin-dev' into go-codegen
Niraj-Kamdar Jul 5, 2023
7f52987
fix: issues
Niraj-Kamdar Jul 5, 2023
208054b
fix: issues
Niraj-Kamdar Jul 5, 2023
12e3925
chore: lint fix
dOrgJelli Jul 5, 2023
f04db97
chore: fix schema-bind test-case.spec.ts
dOrgJelli Jul 5, 2023
9866405
chore: migrate from consideritdone/polywrap-go to polywrap/go-wrap
dOrgJelli Jul 5, 2023
1a3d102
chore: schema-bind tests pass
dOrgJelli Jul 5, 2023
5e45c99
chore: add back compiler & codegen overrides
dOrgJelli Jul 6, 2023
1b1a0ee
chore: building test case
dOrgJelli Jul 6, 2023
483fb8a
wip: checkpoint
Niraj-Kamdar Jul 6, 2023
f38b0bb
wip: working local build
Niraj-Kamdar Jul 6, 2023
255dc1a
wip: local strategy fully working
Niraj-Kamdar Jul 6, 2023
b2a68d4
refactor: remove debug leftover
Niraj-Kamdar Jul 6, 2023
2497dc2
chore: update bindings
dOrgJelli Jul 6, 2023
8259f24
chore: update bind test-case
dOrgJelli Jul 6, 2023
8c8efcd
chore: local build working for test project
dOrgJelli Jul 6, 2023
b21661c
chore: merge origin-dev
dOrgJelli Jul 6, 2023
1fe1067
Merge branch 'origin-dev' into go-codegen
dOrgJelli Jul 6, 2023
015c7aa
chore: vm builds
dOrgJelli Jul 6, 2023
fae0bd6
chore: add cli test cases for golang
dOrgJelli Jul 6, 2023
a00dea3
chore: fix bindings
dOrgJelli Jul 11, 2023
592e6f6
chore: update golang build
dOrgJelli Jul 11, 2023
43d302a
chore: merge origin-dev
dOrgJelli Jul 11, 2023
a13853b
feat: add missing docgen
Niraj-Kamdar Jul 11, 2023
b85a52a
Merge branch 'origin-dev' into go-codegen
dOrgJelli Jul 12, 2023
1258378
feat: add property deps transformer
Niraj-Kamdar Jul 12, 2023
13ca9d1
Merge branch 'go-codegen' of https://github.com/polywrap/cli into go-…
dOrgJelli Jul 12, 2023
5dea0c3
fix: golang binding transform
dOrgJelli Jul 12, 2023
42dafc7
chore: docgen has been removed
dOrgJelli Jul 12, 2023
e7e0bf7
Merge branch 'go-codegen' of https://github.com/polywrap/cli into go-…
dOrgJelli Jul 12, 2023
ff7554b
Merge branch 'origin-dev' into go-codegen
dOrgJelli Jul 12, 2023
f735dfb
chore: update to latest docker image
dOrgJelli Jul 12, 2023
d8cae0e
chore: update bindings to latest go-wrap repo
dOrgJelli Jul 12, 2023
f7184e8
chore: remove todo
dOrgJelli Jul 12, 2023
fb7bdf7
chore: lint fix
dOrgJelli Jul 12, 2023
aeeedc7
Merge branch 'origin-dev' into go-codegen
dOrgJelli Jul 12, 2023
4941dc8
chore: update base-vm-go image version & go-wrap branch
dOrgJelli Jul 12, 2023
7b77346
chore: fix empty argument serialization
dOrgJelli Jul 12, 2023
f9e1c4d
chore: fix array serialization
dOrgJelli Jul 12, 2023
0af14c9
chore: fix bindings
dOrgJelli Jul 13, 2023
362b9c8
chore: fix json binding
dOrgJelli Jul 13, 2023
2f1b66a
chore: fix bindings
dOrgJelli Jul 13, 2023
420114d
chore: fix lint
dOrgJelli Jul 13, 2023
76847b7
chore: remove old test-cases
dOrgJelli Jul 13, 2023
ce4a9c1
chore: remove debug logging
dOrgJelli Jul 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci-golang.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI-Golang

on:
push:
branches:
- origin
- origin-dev
pull_request:

jobs:
Test-Cli:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn install --nonInteractive --frozen-lockfile --prefer-offline

- name: Build
run: yarn build

- name: Test
run: yarn test:golang
working-directory: ./packages/cli
3 changes: 2 additions & 1 deletion packages/cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports = {
modulePathIgnorePatterns: [
"<rootDir>/build",
"<rootDir>/src/__tests__/project/.polywrap",
"<rootDir>/src/__tests__/e2e/build-rs.spec.ts"
"<rootDir>/src/__tests__/e2e/build-rs.spec.ts",
"<rootDir>/src/__tests__/e2e/build-go.spec.ts"
],
testPathIgnorePatterns: [
"<rootDir>/src/__tests__/project/.polywrap"
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/jest.go.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
collectCoverage: true,
preset: "ts-jest",
testEnvironment: "node",
globals: {
"ts-jest": {
diagnostics: false
},
},
modulePathIgnorePatterns: [
"<rootDir>/build",
"<rootDir>/src/__tests__/project/.polywrap"
],
testPathIgnorePatterns: [
"<rootDir>/src/__tests__/project/.polywrap"
],
transformIgnorePatterns: [
"<rootDir>/src/__tests__/project/.polywrap"
],
setupFilesAfterEnv: ["./jest.setup.js"],
testMatch: ["**/build-go.spec.ts"]
};
4 changes: 4 additions & 0 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"commands_build_description": "Build Polywrap Projects (type: interface, wasm)",
"commands_build_error_manifestPathMissing": "{option} option missing {argument} argument",
"commands_build_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_build_error_goModNotFound": "go.mod file not found. Search paths used: {paths}",
"commands_build_error_outputDirMissingPath": "{option} option missing {argument} argument",
"commands_build_error_unsupportedProjectType": "Unsupported project type. You can only build the following project types: {supportedTypes}",
"commands_build_keypressListener_exit": "Exit: [CTRL + C], [ESC], or [Q]",
Expand Down Expand Up @@ -233,6 +234,8 @@
"lib_helpers_deployManifestExt_loadError": "Failed to load deploy manifest extension from {path}",
"lib_helpers_deployManifestExt_loadText": "Load manifest extension from {path}",
"lib_helpers_deployManifestExt_loadWarning": "No manifest extension found in {path}",
"lib_helpers_gomod_unableToLoad": "Unable to load go.mod: {path}",
"lib_helpers_gomod_invalid": "Invalid format of go.mod: {path}",
"lib_helpers_manifest_outputError": "Failed to output manifest to {path}",
"lib_helpers_manifest_outputText": "Manifest written to {path}",
"lib_helpers_manifest_outputWarning": "Warnings writing manifest to {path}",
Expand Down Expand Up @@ -272,6 +275,7 @@
"lib_typescript_tsNodeNotInstalled": "Your project uses typescript, but ts-node is not installed",
"lib_watcher_alreadyWatching": "Watcher session is already in progress. Directory: {dir}",
"lib_wasm_rust_invalidModule": "Module paths must point to Cargo.toml files. Found: {path}",
"lib_wasm_golang_invalidModule": "Module paths must point to go.mod file. Found: {path}",
"lib_docker_invalidImageId": "Invalid docker image ID returned: {imageId}",
"lib_docker_noInstall": "Docker executable not found in PATH",
"lib_infra_unrecognizedModule": "Unrecognized modules: {modules}. Default modules: {defaultModules}",
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"commands_build_description": "Build Polywrap Projects (type: interface, wasm)",
"commands_build_error_manifestPathMissing": "{option} option missing {argument} argument",
"commands_build_error_manifestNotFound": "Manifest not found. Search paths used: {paths}",
"commands_build_error_goModNotFound": "go.mod file not found. Search paths used: {paths}",
"commands_build_error_outputDirMissingPath": "{option} option missing {argument} argument",
"commands_build_error_unsupportedProjectType": "Unsupported project type. You can only build the following project types: {supportedTypes}",
"commands_build_keypressListener_exit": "Exit: [CTRL + C], [ESC], or [Q]",
Expand Down Expand Up @@ -233,6 +234,8 @@
"lib_helpers_deployManifestExt_loadError": "Failed to load deploy manifest extension from {path}",
"lib_helpers_deployManifestExt_loadText": "Load manifest extension from {path}",
"lib_helpers_deployManifestExt_loadWarning": "No manifest extension found in {path}",
"lib_helpers_gomod_unableToLoad": "Unable to load go.mod: {path}",
"lib_helpers_gomod_invalid": "Invalid format of go.mod: {path}",
"lib_helpers_manifest_outputError": "Failed to output manifest to {path}",
"lib_helpers_manifest_outputText": "Manifest written to {path}",
"lib_helpers_manifest_outputWarning": "Warnings writing manifest to {path}",
Expand Down Expand Up @@ -272,6 +275,7 @@
"lib_typescript_tsNodeNotInstalled": "Your project uses typescript, but ts-node is not installed",
"lib_watcher_alreadyWatching": "Watcher session is already in progress. Directory: {dir}",
"lib_wasm_rust_invalidModule": "Module paths must point to Cargo.toml files. Found: {path}",
"lib_wasm_golang_invalidModule": "Module paths must point to go.mod file. Found: {path}",
"lib_docker_invalidImageId": "Invalid docker image ID returned: {imageId}",
"lib_docker_noInstall": "Docker executable not found in PATH",
"lib_infra_unrecognizedModule": "Unrecognized modules: {modules}. Default modules: {defaultModules}",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:e2e:p1": "yarn test:cmd -- ./src/__tests__/e2e/p1/*.spec.ts",
"test:e2e:p2": "yarn test:cmd -- ./src/__tests__/e2e/p2/*.spec.ts",
"test:rust": "yarn test:cmd -- --config ./jest.rs.config.js",
"test:golang": "yarn test:cmd -- --config ./jest.go.config.js",
"test:watch": "yarn test -- --watch"
},
"resolutions": {
Expand Down
72 changes: 72 additions & 0 deletions packages/cli/src/__tests__/e2e/build-go.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { polywrapCli } from "./utils";
import { Commands } from "@polywrap/cli-js";
import { GetPathToCliTestFiles } from "@polywrap/test-cases";
import fs from "fs";
import path from "path";

jest.setTimeout(1500000);

describe("e2e tests for build command", () => {
const testCaseRoot = path.join(GetPathToCliTestFiles(), "build-cmd/wasm/golang");
const testCases = fs
.readdirSync(testCaseRoot, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

const getTestCaseDir = (index: number) =>
path.join(testCaseRoot, testCases[index]);

describe("Image strategy", () => {
it("Builds for go", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "image",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});
const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})

// NOTE: Skipped because CI needs system prequisites: golang
describe.skip("Local strategy", () => {
it("Builds for rust", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "local",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});

const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})

describe("VM strategy", () => {
it("Builds for go", async () => {
const { exitCode: code, stdout: output } = await Commands.build({
strategy: "vm",
verbose: true
}, {
cwd: getTestCaseDir(0),
cli: polywrapCli,
});

const buildDir = `./build`;

expect(code).toEqual(0);
expect(output).toContain(`Artifacts written to ${buildDir}`);
expect(output).toContain(`WRAP manifest written in ${buildDir}/wrap.info`);
});
})
});
1 change: 0 additions & 1 deletion packages/cli/src/__tests__/e2e/p1/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Commands:
codegen|g [options] Generate Code For Polywrap Projects
create|c Create New Projects
deploy|d [options] Deploys Polywrap Projects
docgen|o [options] <action> Generate wrapper documentation
infra|i [options] <action> Modular Infrastructure-As-Code Orchestrator
manifest|m Inspect & Migrade Polywrap Manifests
test|t [options] Execute Tests
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/__tests__/e2e/p1/no-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Commands:
codegen|g [options] Generate Code For Polywrap Projects
create|c Create New Projects
deploy|d [options] Deploys Polywrap Projects
docgen|o [options] <action> Generate wrapper documentation
infra|i [options] <action> Modular Infrastructure-As-Code Orchestrator
manifest|m Inspect & Migrade Polywrap Manifests
test|t [options] Execute Tests
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
polywrapManifestLanguages,
pluginManifestLanguages,
parseWrapperEnvsOption,
parseDirOptionNoDefault,
} from "../lib";
import { CodeGenerator } from "../lib/codegen";
import {
Expand Down Expand Up @@ -48,7 +49,7 @@ export interface BuildCommandOptions extends BaseCommandOptions {
clientConfig: string | false;
wrapperEnvs: string | false;
noCodegen: boolean;
codegenDir: string;
codegenDir: string | false;
watch: boolean;
strategy: `${SupportedStrategies}`;
}
Expand Down Expand Up @@ -112,7 +113,7 @@ export const build: Command = {
wrapperEnvs: options.wrapperEnvs || false,
outputDir: parseDirOption(options.outputDir, defaultOutputDir),
noCodegen: !options.codegen || false,
codegenDir: parseDirOption(options.codegenDir, DEFAULT_CODEGEN_DIR),
codegenDir: parseDirOptionNoDefault(options.codegenDir),
strategy: options.strategy || defaultStrategy,
watch: options.watch || false,
verbose: options.verbose || false,
Expand Down Expand Up @@ -241,7 +242,7 @@ async function run(options: Required<BuildCommandOptions>) {
const codeGenerator = new CodeGenerator({
project,
schemaComposer,
codegenDirAbs: codegenDir,
codegenDirAbs: codegenDir || undefined,
});
const codegenSuccess = await codeGenerator.generate();

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Compiler {
await this._outputWrapManifest();

if (await this._isWasm()) {
// Build & Output: wasm.wrap
// Build & Output: wrap.wasm
await this._buildModules();

// Copy: Resources folder
Expand Down
36 changes: 36 additions & 0 deletions packages/cli/src/lib/build-strategies/BuildOverrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PolywrapManifestLanguage } from "../";

import { PolywrapManifest } from "@polywrap/polywrap-manifest-types-js";
import path from "path";
import fs from "fs";

export interface BuildOverrides {
validateManifest?: (manifest: PolywrapManifest) => Promise<void>;

sourcesSubDirectory?: string;
}

export async function tryGetBuildOverrides(
language: PolywrapManifestLanguage
): Promise<BuildOverrides | undefined> {
const modulePath = path.join(
__dirname,
"..",
"defaults",
"language-overrides",
language,
"index.js"
);
let overrides: BuildOverrides | undefined;

if (fs.existsSync(modulePath)) {
const module = await import(modulePath);

// Get any build overrides for the given build-image
if (module.getBuildOverrides) {
overrides = module.getBuildOverrides() as BuildOverrides;
}
}

return Promise.resolve(overrides);
}
22 changes: 16 additions & 6 deletions packages/cli/src/lib/build-strategies/BuildStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { BuildOverrides, tryGetBuildOverrides } from "./BuildOverrides";
import { PolywrapProject } from "../project";

import fse from "fs-extra";
import path from "path";

export interface BuildStrategyArgs {
export interface BuildStrategyConfig {
project: PolywrapProject;
outputDir: string;
}

export abstract class BuildStrategy<TBuildReturn = unknown> {
protected project: PolywrapProject;
protected outputDir: string;
protected overrides?: BuildOverrides;

constructor({ project, outputDir }: BuildStrategyArgs) {
constructor({ project, outputDir }: BuildStrategyConfig) {
this.project = project;
this.outputDir = outputDir;
}
Expand All @@ -23,25 +25,33 @@ export abstract class BuildStrategy<TBuildReturn = unknown> {

async build(): Promise<TBuildReturn> {
const language = await this.project.getManifestLanguage();
const defaultsOfStrategyUsed = path.join(
const buildStrategyDir = path.join(
__dirname,
"..",
"defaults",
"build-strategies",
language,
this.getStrategyName()
);

// Cache all build strategy files
const strategyUsedCacheDir = this.project.getCachePath(
PolywrapProject.cacheLayout.buildStrategyUsed
);

if (fse.existsSync(strategyUsedCacheDir)) {
fse.removeSync(strategyUsedCacheDir);
}

fse.mkdirSync(strategyUsedCacheDir, { recursive: true });
fse.copySync(buildStrategyDir, strategyUsedCacheDir);

// Check if build overrides exist
this.overrides = await tryGetBuildOverrides(language);

// If they do, ensure the manifest if valid before build starts
if (this.overrides && this.overrides.validateManifest) {
await this.overrides.validateManifest(await this.project.getManifest());
}

fse.copySync(defaultsOfStrategyUsed, strategyUsedCacheDir);
return this.buildSources();
}
}
1 change: 1 addition & 0 deletions packages/cli/src/lib/build-strategies/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./BuildOverrides";
export * from "./BuildStrategy";
export * from "./strategies";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
runCommand,
runCommandSync,
} from "../../system";
import { BuildStrategyArgs, BuildStrategy } from "../BuildStrategy";
import { BuildStrategyConfig, BuildStrategy } from "../BuildStrategy";
import { intlMsg } from "../../intl";
import { logActivity } from "../../logging";

Expand All @@ -21,8 +21,8 @@ type BuildImageId = string;
export class DockerImageBuildStrategy extends BuildStrategy<BuildImageId> {
private _dockerLock: FileLock;

constructor(args: BuildStrategyArgs) {
super(args);
constructor(config: BuildStrategyConfig) {
super(config);

if (!isDockerInstalled(this.project.logger)) {
throw new Error(intlMsg.lib_docker_noInstall());
Expand Down
Loading