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

Add AssemblyScript support to compute init and build commands #160

Merged
merged 10 commits into from
Oct 27, 2020

Conversation

phamann
Copy link
Member

@phamann phamann commented Oct 23, 2020

TL;DR

Adds beta AssemblyScript toolchain support to the Compute@Edge commands fastly compute init and fastly compute build. It uses npm to validate the package and environment and the asc toolchain for compilation.

What

  • Refactor pkg/compute/init.go and pkg/compute/build.go to support multiple languages.
  • Extract common streaming execution logic used by toolchain compilers to pkg/common/exec.
  • Extend the Toolchain interface to better cater for multiple languages.
  • Refactor pkg/compute/rust.go to support new toolchain interface additions.
  • Add new AssemblyScript struct which implements Toolchain interface.
  • Add support to clone startkit templates from git tags instead of branches.
  • Tests!

@phamann phamann added the enhancement New feature or request label Oct 23, 2020
@phamann phamann force-pushed the phamann/assemblyscript branch from e763109 to 2fe6fc8 Compare October 23, 2020 13:07
Comment on lines 25 to 34
type Toolchain interface {
Name() string
DisplayName() string
StarterKits() []StarterKit
SourceDirectory() string
IncludeFiles() []string
Initialize(out io.Writer) error
Verify(out io.Writer) error
Build(out io.Writer, verbose bool) error
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the use of interface methods here to model getters for simple values. Would this be better modelled as a Language struct with an embedded Toolchain interface? Such as:

Suggested change
type Toolchain interface {
Name() string
DisplayName() string
StarterKits() []StarterKit
SourceDirectory() string
IncludeFiles() []string
Initialize(out io.Writer) error
Verify(out io.Writer) error
Build(out io.Writer, verbose bool) error
}
type Toolchain interface {
Initialize(out io.Writer) error
Verify(out io.Writer) error
Build(out io.Writer, verbose bool) error
}
type Language struct {
Name string
DisplayName string
StarterKits []StarterKit
IncludeFiles []string
Toolchain
}
func NewLangauge(name, displayName, string, kits []starterKits, includeFiles []string, toolchain Toolchain) *Language {
// ... etc
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewLangauge -> NewLanguage in your suggestion :)

I personally like the Language struct idea because this NewLanguage function could be where the "metadata"-y bits that I was talking about could be initialized and verified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phamann I like your alternative — structs collect data, and interfaces collect behavior, so your type Language struct seems to best model what's actually going on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @mccurdyc @peterbourgon Have implemented this in 5d59eb8 let me know your thoughts?

Copy link
Member

@thommahoney thommahoney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new abstraction around languages and toolchains 👍

pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
pkg/compute/assemblyscript.go Show resolved Hide resolved
Copy link
Collaborator

@mccurdyc mccurdyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - a couple suggestions and I need to refresh, but didn't want to lose my comments.

I'm paranoid :)

pkg/common/exec.go Outdated Show resolved Hide resolved
pkg/common/exec.go Outdated Show resolved Hide resolved
pkg/common/exec.go Outdated Show resolved Hide resolved
pkg/common/exec.go Outdated Show resolved Hide resolved
pkg/common/exec.go Outdated Show resolved Hide resolved
Comment on lines 174 to 187
// Check if bin directory exists and create if not.
pwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("error getting current working directory: %w", err)
}
binDir := filepath.Join(pwd, "bin")
if err := common.MakeDirectoryIfNotExists(binDir); err != nil {
return fmt.Errorf("error making bin directory: %w", err)
}

npmdir, err := getNpmBinPath()
if err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion - thoughts on pulling these "metadata"-y bits into some centralized "initialization" function that gets called once and sets some "metadata" fields on like a config struct or something so that we don't have to have these checks in multiple places.

An additional benefit of this would be that the functions are more focused on what they are supposed to be doing --- e.g., "building" --- and less on validating the environment.


A valid counter argument to this would be then you have dependencies on the metadata fields being set and the functions --- e.g., Build --- are not entirely self-contained.

pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
Comment on lines 25 to 34
type Toolchain interface {
Name() string
DisplayName() string
StarterKits() []StarterKit
SourceDirectory() string
IncludeFiles() []string
Initialize(out io.Writer) error
Verify(out io.Writer) error
Build(out io.Writer, verbose bool) error
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewLangauge -> NewLanguage in your suggestion :)

I personally like the Language struct idea because this NewLanguage function could be where the "metadata"-y bits that I was talking about could be initialized and verified.

pkg/compute/compute_integration_test.go Show resolved Hide resolved
pkg/compute/compute_integration_test.go Show resolved Hide resolved
phamann and others added 3 commits October 23, 2020 15:33
pkg/common/file.go Outdated Show resolved Hide resolved
pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
pkg/compute/assemblyscript.go Outdated Show resolved Hide resolved
pkg/compute/build.go Outdated Show resolved Hide resolved
pkg/compute/compute_integration_test.go Outdated Show resolved Hide resolved
pkg/common/exec.go Outdated Show resolved Hide resolved
pkg/common/exec.go Show resolved Hide resolved
pkg/common/exec.go Show resolved Hide resolved
Copy link
Collaborator

@mccurdyc mccurdyc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants