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

auto unpack psh_host.dll dependency #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ steps:
# script: 'choco install -y golang --no-progress;
# refreshenv ;
# copy native-powershell\host.h .\pkg\powershell\ ;
# copy native-powershell\x64\Release\psh_host.dll . ;
# copy native-powershell\x64\Release\psh_host.dll .\pkg\powershell\ ;
# copy native-powershell\x64\Release\psh_host.dll .\tests\benchmarks\ ;'
- task: PowerShell@2
displayName: Copy psh_host
inputs:
targetType: 'inline'
script: '
copy bin\psh_host.dll . ;
copy bin\psh_host.dll .\pkg\powershell\ ;
copy bin\psh_host.dll .\tests\benchmarks\ ;'

- task: PowerShell@2
displayName: "Setup Go environment"
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ go 1.12

require (
github.com/KnicKnic/go-windows v0.0.2
github.com/KnicKnic/temp-dll v0.0.0-20200907062319-b1f2fa734212
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a
golang.org/x/tools v0.0.0-20200904185747-39188db58858 // indirect
k8s.io/klog v1.0.0
)
34 changes: 34 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
github.com/KnicKnic/temp-dll v0.0.0-20200907062319-b1f2fa734212 h1:WI6NHR8lAjkfanBprm4zZKcVnyIPPMZWeTiTjubdoj0=
github.com/KnicKnic/temp-dll v0.0.0-20200907062319-b1f2fa734212/go.mod h1:rZZMP7gg9viuxMiKhbTyI1PQmGk96kAV3D36C9p19gc=
github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a h1:i47hUS795cOydZI4AwJQCKXOr4BvxzvikwDoDtHhP2Y=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200904185747-39188db58858 h1:xLt+iB5ksWcZVxqc+g9K41ZHy+6MKWfXCDsjSThnsPA=
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/KnicKnic/go-windows v0.0.2 h1:8979vGZ1dDMbTKR5aTZyluGDAzHnVlWZJ8y68DPTks4=
github.com/KnicKnic/go-windows v0.0.2/go.mod h1:bq9qyrkvAvMH2HPlkix2bE/eDuRz1kzwyoV/ieVhqK0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
184 changes: 184 additions & 0 deletions pkg/embedded/binaries.go

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions pkg/embedded/generator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:generate go run main.go
package main

import (
"log"
"net/http"
"os"

"github.com/shurcooL/httpfs/filter"
"github.com/shurcooL/vfsgen"
)

var Assets http.FileSystem = http.Dir("../../../bin")

func main() {

// Keep only "/target/dir" and its contents.
fs := filter.Keep(Assets, func(path string, fi os.FileInfo) bool {
return path == "/psh_host.dll" || path == "/"
})

err := vfsgen.Generate(fs, vfsgen.Options{
PackageName: "embedded",
BuildTags: "",
VariableName: "Binaries",
Filename: "../binaries.go",
})
if err != nil {
log.Fatalln(err)
}
}
12 changes: 12 additions & 0 deletions pkg/embedded/psh_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package embedded

import "net/http"

// OpenPshHostDll opens a /psh_host.dll
func OpenPshHostDll() http.File {
file, err := Binaries.Open("/psh_host.dll")
if err != nil {
panic(err)
}
return file
}
9 changes: 8 additions & 1 deletion pkg/powershell/zpsh_host.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Features:
1. Call from powershell to golang (via special Send-HostCommand commandlet)
1. Easy logging - Trap host output in powershell and call custom logging routines in golang
1. Uses syscall - so do not need to use cGo
1. Single file executable - unpacks its dependencies

# Status

Expand Down Expand Up @@ -87,10 +88,8 @@ This project has a dependency on [native-powershell](https://github.com/KnicKnic

### Using native-powershell

1. Simply fetch the dependencies, `go get -d .` and then make sure to build, `go build`
1. Copy the precompiled psh_host.dll into your location so it can be found when running the app
1. cmd - `copy %GOPATH%\src\github.com\KnicKnic\go-powershell\bin\psh_host.dll .`
1. powershell - `copy "$($env:GOPATH)\src\github.com\KnicKnic\go-powershell\bin\psh_host.dll" .`
1. go to pkg/embedded/generator and run go generate .
1. This will update the `/bin/psh_host.dll` to be in `/pkg/embedded/binaries.go`
1. I ended up checking in the psh_host.dll and host.h (to make things easy)
1. I could not find a better way to go about this and still have things be easy.

Expand Down