Skip to content

Commit

Permalink
feat: add external plugin to build engine
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/cli/cmd_new.go
#	internal/buildengine/deps.go
#	internal/buildengine/engine.go
#	internal/buildengine/languageplugin/go_integration_test.go
#	internal/buildengine/languageplugin/go_plugin_integration_test.go
#	internal/buildengine/languageplugin/go_plugin_tests.go
#	internal/buildengine/languageplugin/plugin.go
#	internal/buildengine/plugin_go_integration_test.go
  • Loading branch information
matt2e committed Oct 8, 2024
1 parent 28ac330 commit 70b8148
Show file tree
Hide file tree
Showing 13 changed files with 4,840 additions and 137 deletions.
1,825 changes: 1,697 additions & 128 deletions backend/protos/xyz/block/ftl/v1/language/language.pb.go

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions backend/protos/xyz/block/ftl/v1/language/language.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,87 @@ syntax = "proto3";

package xyz.block.ftl.v1.language;

import "google/protobuf/any.proto";
import "xyz/block/ftl/v1/ftl.proto";
import "xyz/block/ftl/v1/schema/schema.proto";

option go_package = "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/language;languagepb";
option java_multiple_files = true;

message Metadata {
// Universal metadata
string name = 1;
string language = 2;

// Language metadata contains any metadata specific to a specific language.
// TODO: revisit type...
google.protobuf.Any LanguageMetadata = 3;
}

message ProjectConfig {
string path = 1;
string name = 2;
bool noGit = 3;
bool hermit = 4;
}

// TODO: docs
message GetCreateModuleFlagsRequest {
string language = 1;
}

message GetCreateModuleFlagsResponse {
message Flag {
string name = 1;
string help = 2;
optional string envar = 3;
// short must be a single character
optional string short = 4;
optional string placeholder = 5;
optional string default = 6;
}
repeated Flag flags = 1;
}

// Request to create a new module.
message CreateModuleRequest {
string name = 1;
string path = 2;

ProjectConfig projectConfig = 3;

// TODO: revisit type...
google.protobuf.Any Flags = 4;
}

// Response to a create module request.
message CreateModuleResponse {}

message DependenciesRequest {
string path = 1;
Metadata metadata = 2;
}

message DependenciesResponse {
repeated string modules = 1;
}

// Response to a dependency extraction request.
message DependencyUpdate {
repeated string modules = 1;
}

// TODO: docs
message BuildContextUpdatedRequest {
// TODO: explain
string buildRequestId = 1;

optional Metadata metadata = 2;
optional schema.Schema schema = 3;
}

message BuildContextUpdatedResponse {}

message Error {
enum ErrorLevel {
INFO = 0;
Expand All @@ -23,3 +99,103 @@ message Error {
message ErrorList {
repeated Error errors = 1;
}

// Request to build a module.
message BuildRequest {
// TODO: explain
string buildRequestId = 1;

// the root path for the module
string path = 2;
// the root path for the FTL project
string project_path = 3;
// indicates whether to watch for changes to the module
// TODO: rename to automaticRebuilds
bool watch = 4;

Metadata metadata = 5;
schema.Schema schema = 6;
}

message AutoRebuildStarted {}

// Response to a build request.
message BuildResult {
optional string buildRequestId = 1;
// module schema for the built module
// only set if the build was successful
optional schema.Module module = 2;
// paths for files/directories to be deployed
repeated string deploy = 3;
// errors and warnings encountered during the build
ErrorList errors = 4;

// TODO: dockerfile or docker image name...
// TODO: add a way to return what schema / metadata version this was based on
}

enum LogLevel {
DEBUG = 0;
INFO = 1;
WARN = 2;
ERROR = 3;
}

// Log message from the language service.
message LogMessage {
string message = 1;
LogLevel level = 2;
}

// Every type of message that can be streamed from the language service for a build.
message BuildEvent {
oneof event {
DependencyUpdate dependency_update = 1;
AutoRebuildStarted auto_rebuild_started = 2;
BuildResult build_result = 3;
LogMessage log_message = 4;
}
}

// LanguageService allows a plugin to add support for a programming language.
service LanguageService {
// Ping service for readiness.
rpc Ping(xyz.block.ftl.v1.PingRequest) returns (xyz.block.ftl.v1.PingResponse) {
option idempotency_level = NO_SIDE_EFFECTS;
}

// TODO: docs
rpc GetCreateModuleFlags(GetCreateModuleFlagsRequest) returns (GetCreateModuleFlagsResponse);

// Generates files for a new empty module with the requested name
rpc CreateModule(CreateModuleRequest) returns (CreateModuleResponse);

// Extract dependencies for a module
rpc GetDependencies(DependenciesRequest) returns (DependenciesResponse);

// MetadataUpdated is called whenever the metadata for a module is updated.
// TODO: explain this only happens while watching?
// TODO: merge with schema updated... to avoid double builds if both change
// rpc MetadataUpdated(MetadataUpdatedRequest) returns (MetadataUpdatedResponse);

// SchemaUpdated is called whenever the relevant part of a schema is updated.
//
// The schema is not the full schema, rather it only modules in this module's dependency graph.
// It does not contain the schema for this plugin's module.
//
// Language plugins should hold on to the latest schema they have seen.
// SchemaUpdated is called:
// - after ExtractDependencies and before Build (if there are any dependencies)
// - when a dependant module is updated
// - when the module's dependancies change
//
// TODO: explain this only happens while watching?
// rpc SchemaUpdated(SchemaUpdatedRequest) returns (SchemaUpdatedResponse);

rpc BuildContextUpdated(BuildContextUpdatedRequest) returns (BuildContextUpdatedResponse);

// Build the module
// The request can also indicate whether the plugin should watch for changes to the module and automatically rebuild
// The response stream can send LogMessages and BuildResults, and ends with a BuildResponse
rpc Build(BuildRequest) returns (stream BuildEvent);
}
Loading

0 comments on commit 70b8148

Please sign in to comment.