Skip to content

Commit

Permalink
Unix support
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Mar 9, 2024
1 parent 0035f93 commit 95e0570
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 27 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ devenv.local.nix

/target

.obsidian

/composed1.wat
/composed2.wat
/my-file
/pulumi-language-wasm/pulumi-language-wasm.exe

.idea/

Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.obsidian
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

./run.sh

cargo run -- run --wasm target/wasm32-wasi/debug/composed2.wasm
2 changes: 2 additions & 0 deletions pulumi-language-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/pulumi-language-wasm.exe
/pulumi-language-wasm
9 changes: 9 additions & 0 deletions pulumi-language-wasm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

pulumi plugin rm language wasm -y

go build

pulumi plugin install language wasm 1.0 --file ./pulumi-language-wasm
7 changes: 2 additions & 5 deletions pulumi-language-wasm/executors/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ type WasmExecutorOptions struct {
// Current working directory. Abstract to enable testing.
WD fsys.ParentFS

// The absolute path to the bootstrap library jar
// which should be shipped together with the main language host binary
BootstrapLibJarPath string

// The value of `runtime.options.binary` setting from
// `Pulumi.yaml`. Optional.
Binary string
Expand All @@ -62,12 +58,13 @@ type wasmExecutorFactory interface {
func NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) {
e, err := combineWasmExecutorFactories(
&windows{},
&unix{},
).NewWasmExecutor(opts)
if err != nil {
return nil, err
}
if e == nil {
return nil, fmt.Errorf("failed to configure executor, tried: entrypoint.bat")
return nil, fmt.Errorf("failed to configure executor, tried: entrypoint.bat, entrypoint.sh")
}
return e, nil
}
Expand Down
38 changes: 38 additions & 0 deletions pulumi-language-wasm/executors/executor_unix_os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022, Pulumi Corporation. All rights reserved.

package executors

import (
"github.com/andrzejressel/pulumi-wasm/pulumi-language-wasm/fsys"
"runtime"
)

type unix struct{}

var _ wasmExecutorFactory = &unix{}

func (s unix) NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) {
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
return nil, nil
}
probePaths := []string{opts.UseExecutor}
if opts.UseExecutor == "" {
probePaths = []string{"./entrypoint.sh"}
}
cmd, err := fsys.LookPath(opts.WD, probePaths...)
if err != nil {
return nil, err
}
return s.newWasmCliExecutor(cmd)
}

func (unix) newWasmCliExecutor(script string) (*WasmExecutor, error) {
return &WasmExecutor{
Name: script,
Cmd: "bash",
BuildArgs: []string{"-c", script, "build"},
RunArgs: []string{"-c", script, "run"},
PluginArgs: []string{"-c", script, "plugin"},
VersionArgs: []string{"-c", script, "version"},
}, nil
}
4 changes: 2 additions & 2 deletions pulumi-language-wasm/executors/executor_windows_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func (s windows) NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error
if err != nil {
return nil, err
}
return s.newWasmCliExecutor(cmd, opts.BootstrapLibJarPath)
return s.newWasmCliExecutor(cmd)
}

func (windows) newWasmCliExecutor(script string, bootstrapLibJarPath string) (*WasmExecutor, error) {
func (windows) newWasmCliExecutor(script string) (*WasmExecutor, error) {
return &WasmExecutor{
Name: script,
Cmd: "cmd",
Expand Down
23 changes: 7 additions & 16 deletions pulumi-language-wasm/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2022, Pulumi Corporation. All rights reserved.

// The implementation is heavily based on basom one.
// The implementation is heavily based on besom one.

package main

Expand All @@ -14,7 +14,6 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -59,17 +58,10 @@ func main() {
cmdutil.Exit(fmt.Errorf("could not get the working directory: %w", err))
}

execPath, err := os.Executable()
if err != nil {
cmdutil.Exit(fmt.Errorf("could not get the path of the executable: %w", err))
}
bootstrapLibJarPath := filepath.Join(filepath.Dir(execPath), "bootstrap.jar") // TODO: hardocoded jar name

wasmExecOptions := executors.WasmExecutorOptions{
Binary: binary,
UseExecutor: useExecutor,
WD: fsys.DirFS(wd),
BootstrapLibJarPath: bootstrapLibJarPath,
Binary: binary,
UseExecutor: useExecutor,
WD: fsys.DirFS(wd),
}

// Optionally pluck out the engine, so we can do logging, etc.
Expand Down Expand Up @@ -449,10 +441,9 @@ func (host *wasmLanguageHost) About(ctx context.Context, _ *emptypb.Empty) (*pul
}

javaExec, err := executors.NewWasmExecutor(executors.WasmExecutorOptions{
UseExecutor: "jar",
WD: host.execOptions.WD,
BootstrapLibJarPath: host.execOptions.BootstrapLibJarPath,
Binary: host.execOptions.Binary,
UseExecutor: "jar",
WD: host.execOptions.WD,
Binary: host.execOptions.Binary,
})
if err != nil {
return nil, err
Expand Down
26 changes: 26 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e

cargo component build -p wasm_common
cargo component build -p pulumi_wasm
cargo component build -p pulumi_wasm_random
cargo component build -p pulumi_rust_wasm
cargo component build -p pulumi_wasm_main
cargo build


cp "target/wasm32-wasi/debug/pulumi_wasm.wasm" "target/wasm32-wasi/debug/pulumi-wasm.wasm"
cp "target/wasm32-wasi/debug/pulumi_wasm_main.wasm" "target/wasm32-wasi/debug/pulumi-wasm-main.wasm"
cp "target/wasm32-wasi/debug/pulumi_wasm_random.wasm" "target/wasm32-wasi/debug/pulumi-wasm-random.wasm"
cp "target/wasm32-wasi/debug/pulumi_rust_wasm.wasm" "target/wasm32-wasi/debug/pulumi-rust-wasm.wasm"


wasm-tools compose -o target/wasm32-wasi/debug/composed1.wasm target/wasm32-wasi/debug/pulumi-wasm-main.wasm -d target/wasm32-wasi/debug/pulumi-wasm-random.wasm
wasm-tools compose -o target/wasm32-wasi/debug/composed2.wasm target/wasm32-wasi/debug/composed1.wasm -d target/wasm32-wasi/debug/pulumi-wasm.wasm
cargo run -- compile --wasm target/wasm32-wasi/debug/composed2.wasm --output target/wasm32-wasi/debug/composed2.cwasm
#wasmtime compile -D debug-info=y,coredump=y,address-map=y -o target/wasm32-wasi/debug/composed2.cwasm target/wasm32-wasi/debug/composed2.wasm || exit /b 1

wasm-tools component wit target/wasm32-wasi/debug/composed2.wasm
wasm-tools print target/wasm32-wasi/debug/composed1.wasm > composed1.wat
wasm-tools print target/wasm32-wasi/debug/composed2.wasm > composed2.wat

0 comments on commit 95e0570

Please sign in to comment.