Skip to content

Commit

Permalink
TinyGo Native Iotas and Code Generation enhancements (#49)
Browse files Browse the repository at this point in the history
* TinyGo Code generation enhancements and expanded testing scenarios in Apex

* Removing returned instances until the spec if fleshed out

* Version bump apexlang_codegen
  • Loading branch information
pkedy authored Feb 15, 2023
1 parent 3d92ec7 commit 9373806
Show file tree
Hide file tree
Showing 66 changed files with 10,576 additions and 1,273 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,12 @@ jobs:
- name: Install Apex CLI
run: deno install -A --unstable -f -n apex https://deno.land/x/apex_cli/apex.ts

# - run: npm install
# working-directory: ./codegen

# - run: npm run test
# working-directory: ./codegen

# #- run: npm run lint
# - run: npm run build
# working-directory: ./codegen

# - name: Install codegen module
# run: apex install file:.
# working-directory: ./codegen
- name: Run codegen tests
run: apex test
working-directory: ./codegen

- name: Bundle module and dependencies
run: deno bundle src/mod.ts bundle.js
run: apex build
working-directory: ./codegen

- name: Generator diff test
Expand Down
1 change: 1 addition & 0 deletions codegen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/testdata/*/actual/*

# compiled output
bundle.js
dist
tmp
/out-tsc
Expand Down
3 changes: 2 additions & 1 deletion codegen/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"editor.formatOnSave": true,
"deno.enable": true,
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
}
11 changes: 11 additions & 0 deletions codegen/apex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tasks:
build:
cmds:
- deno bundle src/mod.ts bundle.js

test:
cmds:
- deno fmt --check src/ test/
- deno lint src/
- deno check --unstable src/mod.ts
- deno test --allow-env test/utils.test.ts
22 changes: 0 additions & 22 deletions codegen/justfile

This file was deleted.

2 changes: 1 addition & 1 deletion codegen/src/deps/codegen/go.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].6/go/mod.ts";
export * from "https://deno.land/x/[email protected].9/go/mod.ts";
2 changes: 1 addition & 1 deletion codegen/src/deps/codegen/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].6/mod.ts";
export * from "https://deno.land/x/[email protected].9/mod.ts";
2 changes: 1 addition & 1 deletion codegen/src/deps/codegen/rust.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].6/rust/mod.ts";
export * from "https://deno.land/x/[email protected].9/rust/mod.ts";
2 changes: 1 addition & 1 deletion codegen/src/deps/codegen/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].6/utils/mod.ts";
export * from "https://deno.land/x/[email protected].9/utils/mod.ts";
2 changes: 1 addition & 1 deletion codegen/src/deps/core/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/x/[email protected].2/mod.ts';
export * from "https://deno.land/x/[email protected].3/mod.ts";
2 changes: 1 addition & 1 deletion codegen/src/deps/core/model.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].2/model/mod.ts";
export * from "https://deno.land/x/[email protected].3/model/mod.ts";
7 changes: 5 additions & 2 deletions codegen/src/rust/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Configuration,
TaskDefinition,
} from "https://deno.land/x/[email protected].15/src/config.ts";
} from "https://deno.land/x/[email protected].18/src/config.ts";
import * as apex from "../deps/core/mod.ts";
import * as rust from "../deps/codegen/rust.ts";
import { Context, Operation } from "../deps/core/model.ts";
Expand Down Expand Up @@ -37,9 +37,12 @@ export default function (
config.config.name ||= module;
try {
const cargoToml = Deno.readTextFileSync("./Cargo.toml");
// deno-lint-ignore no-explicit-any
const cargo = parse(cargoToml) as any;
config.config.name ||= cargo.package.name;
} catch {}
} catch {
// Ignore
}
if (!config.config.name) {
throw new Error(
"No name provided in config, and no Cargo.toml found with a name",
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/rust/visitors/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Type,
Union,
Writer,
} from '../../deps/core/model.ts';
} from "../../deps/core/model.ts";

export type VisitorTypes = Alias | Type | Union | Enum | Interface;

Expand Down
1 change: 0 additions & 1 deletion codegen/src/rust/visitors/provider-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Context,
Interface,
Kind,
ObjectMap,
Operation,
Stream,
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/templates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Template } from "https://deno.land/x/[email protected].15/src/config.ts";
import { Template } from "https://deno.land/x/[email protected].18/src/config.ts";

const template: Template = {
info: {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/templates/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Template } from "https://deno.land/x/[email protected].15/src/config.ts";
import { Template } from "https://deno.land/x/[email protected].18/src/config.ts";

const template: Template = {
info: {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/templates/rust/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["apexlang.apexlang"]
}
}
2 changes: 1 addition & 1 deletion codegen/src/templates/rust/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
FSStructure,
Template,
} from "https://deno.land/x/[email protected].15/src/config.ts";
} from "https://deno.land/x/[email protected].18/src/config.ts";

const importUrl = new URL(".", import.meta.url);
function urlify(relpath: string): string {
Expand Down
7 changes: 6 additions & 1 deletion codegen/src/templates/tinygo/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"task.allowAutomaticTasks": "on"
"task.allowAutomaticTasks": "on",
"editor.formatOnSave": true,
"deno.enable": true,
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
2 changes: 1 addition & 1 deletion codegen/src/templates/tinygo/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
FSStructure,
Template,
} from "https://deno.land/x/[email protected].15/src/config.ts";
} from "https://deno.land/x/[email protected].18/src/config.ts";

const importUrl = new URL(".", import.meta.url);
function urlify(relpath: string): string {
Expand Down
36 changes: 36 additions & 0 deletions codegen/src/tinygo/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,46 @@ export const primitiveTransformers = new Map<string, string>([
["bytes", "transform.Bytes"],
]);

export const primitiveToBytes = new Map<string, string>([
["bool", "BoolToBytes"],
["string", "StringToBytes"],
["datetime", "TimeToBytes"],
["i8", "I8ToBytes"],
["u8", "U8ToBytes"],
["i16", "I16ToBytes"],
["u16", "U16ToBytes"],
["i32", "I32ToBytes"],
["u32", "U32ToBytes"],
["i64", "I64ToBytes"],
["u64", "U64ToBytes"],
["f32", "F32ToBytes"],
["f64", "F64ToBytes"],
["bytes", "BytesToBytes"],
]);

export const primitiveDecode = new Map<string, string>([
["bool", "BoolDecode"],
["string", "StringDecode"],
["datetime", "TimeDecode"],
["i8", "Int8Decode"],
["u8", "Uint8Decode"],
["i16", "Int16Decode"],
["u16", "Uint16Decode"],
["i32", "Int32Decode"],
["u32", "Uint32Decode"],
["i64", "Int64Decode"],
["u64", "Uint64Decode"],
["f32", "Float32Decode"],
["f64", "Float64Decode"],
["bytes", "BytesDecode"],
]);

export const IMPORTS = {
context: "context",
errors: "errors",
binary: "encoding/binary",
guest: "github.com/nanobus/iota/go/transport/wasmrs/guest",
rsocket: "github.com/nanobus/iota/go/transport/rsocket",
invoke: "github.com/nanobus/iota/go/invoke",
msgpack: "github.com/nanobus/iota/go/msgpack",
convert: "github.com/nanobus/iota/go/msgpack/convert",
Expand Down
4 changes: 1 addition & 3 deletions codegen/src/tinygo/export_visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import {
Context,
} from "../deps/core/model.ts";
import { Context } from "../deps/core/model.ts";
import { GoVisitor } from "../deps/codegen/go.ts";
import { WrappersVisitor } from "./wrappers_visitor.ts";
import { RegisterVisitor } from "./register_visitor.ts";
Expand Down
Loading

0 comments on commit 9373806

Please sign in to comment.