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

Windows support #73

Open
wants to merge 7 commits into
base: main
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
115 changes: 89 additions & 26 deletions .circleci/config.pkl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.0.2#/PklCI.pkl"
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.1.1#/PklCI.pkl"

import "pkl:semver"

local testJobs = jobs.keys.filter((it) -> it.startsWith("test"))

Expand All @@ -14,13 +16,23 @@ local class PklDistribution {
/// The version of this distribution
version: String

/// The parsed semver.
fixed _version: semver.Version = semver.parseOrNull(version)!!

/// The URL to download this distribution
fixed downloadUrl: String = "https://github.com/apple/pkl/releases/download/\(version)/pkl-linux-amd64"

/// The URL to download this distribution
fixed downloadUrlWindows: String =
if (_version.minor < 26) throw("Pkl \(version) is not supported on Windows")
else "https://github.com/apple/pkl/releases/download/\(version)/pkl-windows-amd64.exe"
}

local distributionLatest: PklDistribution = new { version = "0.26.0" }

local pklDistributions: Listing<PklDistribution> = new {
new { version = "0.25.3" }
new { version = "0.26.0" }
distributionLatest
}

release = (buildWorkflow) {
Expand Down Expand Up @@ -48,52 +60,103 @@ triggerDocsBuild = "release"
triggerPackageDocsBuild = "release"

jobs {
for (distribution in pklDistributions) {
["test-pkl-\(distribution.version.replaceAll(".", "-"))"] = (goJob) {
steps {
new RunStep {
name = "go test"
command = """
curl -L -o pkl.bin '\(distribution.downloadUrl)'
chmod +x pkl.bin
export PKL_EXEC=$(pwd)/pkl.bin
go install github.com/jstemmer/go-junit-report/v2@latest
echo "Running Pkl unit tests"
$PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl
echo "Running Pkl snippet tests"
./scripts/test_snippets.sh
echo "Running Go unit tests"
go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml
"""
}
new StoreTestResults {
path = "test-results"
}
// for (distribution in pklDistributions) {
// ["test-pkl-\(distribution.version.replaceAll(".", "-"))"] = (goJob) {
// steps {
// new RunStep {
// name = "go test"
// command = """
// curl -L -o pkl.bin '\(distribution.downloadUrl)'
// chmod +x pkl.bin
// export PKL_EXEC=$(pwd)/pkl.bin
// go install github.com/jstemmer/go-junit-report/v2@latest
// echo "Running Pkl unit tests"
// $PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl
// echo "Running Pkl snippet tests"
// ./scripts/test_snippets.sh
// echo "Running Go unit tests"
// go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml
// """
// }
// new StoreTestResults {
// path = "test-results"
// }
// }
// }
// }
["test-windows"] {
machine {
image = "windows-server-2022-gui:current"
}
resource_class = "windows.medium"
steps {
"checkout"
new RunStep {
name = "go test"
shell = "powershell.exe"
command = #"""
echo "Downloading Go"
Invoke-WebRequest "https://go.dev/dl/go1.21.11.windows-386.msi" -OutFile go.exe

echo "Installing Go"
$pkg = "$PWD\go.exe"
Start-Process msiexec "/i $pkg /qn";

echo "Installing Pkl"
Invoke-WebRequest "\#(distributionLatest.downloadUrlWindows)" -OutFile pkl.exe
$env:PKL_EXEC = "$PWD\pkl.exe"

echo "Running Pkl unit tests"
.\pkl test --junit-reports test-results\ --project-dir codegen\src\

echo "Installing go-junit-report"
go install github.com/jstemmer/go-junit-report/v2@latest

echo "Running Go unit tests"
go test -v .\... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results\go-test-results.xml
"""#
}
}
}
["build-pkl-gen-go"] = (goJob) {
steps {
for (os in List("macos", "linux")) {
for (os in List("macos", "linux", "windows")) {
for (arch in List("amd64", "aarch64")) {
new RunStep {
name = "go build \(os) \(arch)"
environment {
["GOOS"] = if (os == "linux") os else "darwin"
["GOOS"] = if (os == "linux" || os == "windows") os else "darwin"
["GOARCH"] = if (arch == "amd64") arch else "arm64"
}
local ext = if (os == "windows") "exe" else "bin"
command = #"""
# strip preceding "v"
VERSION="${CIRCLE_TAG:1}"

go build \
-o out/pkl-gen-go/pkl-gen-go-\#(os)-\#(arch).bin \
-o out/pkl-gen-go/pkl-gen-go-\#(os)-\#(arch).\#(ext) \
-ldflags="-X 'main.Version=$VERSION'" \
cmd/pkl-gen-go/pkl-gen-go.go
"""#
}
}
}
new RunStep {
name = "go build windows amd64"
environment {
["GOOS"] = "windows"
["GOARCH"] = "amd64"
}
command = #"""
# strip preceding "v"
VERSION="${CIRCLE_TAG:1}"

go build \
-o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \
-ldflags="-X 'main.Version=$VERSION'" \
cmd/pkl-gen-go/pkl-gen-go.go
"""#
}
new PersistToWorkspaceStep {
root = "."
paths {
Expand Down
120 changes: 67 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,35 @@ version: '2.1'
orbs:
pr-approval: apple/pr-approval@0.1.0
jobs:
test-pkl-0-25-3:
test-windows:
steps:
- checkout
- run:
command: |-
curl -L -o pkl.bin 'https://github.com/apple/pkl/releases/download/0.25.3/pkl-linux-amd64'
chmod +x pkl.bin
export PKL_EXEC=$(pwd)/pkl.bin
go install github.com/jstemmer/go-junit-report/v2@latest
echo "Downloading Go"
Invoke-WebRequest "https://go.dev/dl/go1.21.11.windows-386.msi" -OutFile go.exe

echo "Installing Go"
$pkg = "$PWD\go.exe"
Start-Process msiexec "/i $pkg /qn";

echo "Installing Pkl"
Invoke-WebRequest "https://github.com/apple/pkl/releases/download/0.26.0/pkl-windows-amd64.exe" -OutFile pkl.exe
$env:PKL_EXEC = "$PWD\pkl.exe"

echo "Running Pkl unit tests"
$PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl
echo "Running Pkl snippet tests"
./scripts/test_snippets.sh
echo "Running Go unit tests"
go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml
name: go test
- store_test_results:
path: test-results
docker:
- image: cimg/go:1.21
test-pkl-0-26-0:
steps:
- checkout
- run:
command: |-
curl -L -o pkl.bin 'https://github.com/apple/pkl/releases/download/0.26.0/pkl-linux-amd64'
chmod +x pkl.bin
export PKL_EXEC=$(pwd)/pkl.bin
.\pkl test --junit-reports test-results\ --project-dir codegen\src\

echo "Installing go-junit-report"
go install github.com/jstemmer/go-junit-report/v2@latest
echo "Running Pkl unit tests"
$PKL_EXEC test --junit-reports test-results/ codegen/src/tests/*.pkl
echo "Running Pkl snippet tests"
./scripts/test_snippets.sh

echo "Running Go unit tests"
go test -race -v ./... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results/go-test-results.xml
go test -v .\... 2>&1 | go-junit-report -iocopy -set-exit-code -out test-results\go-test-results.xml
name: go test
- store_test_results:
path: test-results
docker:
- image: cimg/go:1.21
shell: powershell.exe
resource_class: windows.medium
machine:
image: windows-server-2022-gui:current
build-pkl-gen-go:
steps:
- checkout
Expand Down Expand Up @@ -98,6 +87,45 @@ jobs:
environment:
GOOS: linux
GOARCH: arm64
- run:
command: |-
# strip preceding "v"
VERSION="${CIRCLE_TAG:1}"

go build \
-o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \
-ldflags="-X 'main.Version=$VERSION'" \
cmd/pkl-gen-go/pkl-gen-go.go
name: go build windows amd64
environment:
GOOS: windows
GOARCH: amd64
- run:
command: |-
# strip preceding "v"
VERSION="${CIRCLE_TAG:1}"

go build \
-o out/pkl-gen-go/pkl-gen-go-windows-aarch64.exe \
-ldflags="-X 'main.Version=$VERSION'" \
cmd/pkl-gen-go/pkl-gen-go.go
name: go build windows aarch64
environment:
GOOS: windows
GOARCH: arm64
- run:
command: |-
# strip preceding "v"
VERSION="${CIRCLE_TAG:1}"

go build \
-o out/pkl-gen-go/pkl-gen-go-windows-amd64.exe \
-ldflags="-X 'main.Version=$VERSION'" \
cmd/pkl-gen-go/pkl-gen-go.go
name: go build windows amd64
environment:
GOOS: windows
GOARCH: amd64
- persist_to_workspace:
root: '.'
paths:
Expand Down Expand Up @@ -212,10 +240,7 @@ workflows:
type: approval
- pr-approval/authenticate:
context: pkl-pr-approval
- test-pkl-0-25-3:
requires:
- hold
- test-pkl-0-26-0:
- test-windows:
requires:
- hold
when:
Expand All @@ -224,47 +249,36 @@ workflows:
pattern: ^pull/\d+(/head)?$
main:
jobs:
- test-pkl-0-25-3
- test-pkl-0-26-0
- test-windows
- build-pkl-gen-go:
requires:
- test-pkl-0-25-3
- test-pkl-0-26-0
- test-windows
- build-pkl-package:
requires:
- test-pkl-0-25-3
- test-pkl-0-26-0
- test-windows
when:
equal:
- main
- << pipeline.git.branch >>
release:
jobs:
- test-pkl-0-25-3:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- test-pkl-0-26-0:
- test-windows:
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- build-pkl-gen-go:
requires:
- test-pkl-0-25-3
- test-pkl-0-26-0
- test-windows
filters:
branches:
ignore: /.*/
tags:
only: /^v?\d+\.\d+\.\d+$/
- build-pkl-package:
requires:
- test-pkl-0-25-3
- test-pkl-0-26-0
- test-windows
filters:
branches:
ignore: /.*/
Expand Down
27 changes: 0 additions & 27 deletions pkl/module_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package pkl

import (
"net/url"
"os"
"path"
)

// ModuleSource represents a source for Pkl evaluation.
Expand All @@ -34,31 +32,6 @@ type ModuleSource struct {
Contents string
}

// FileSource builds a ModuleSource, treating its arguments as paths on the file system.
//
// If the provided path is not an absolute path, it will be resolved against the current working
// directory.
//
// If multiple path arguments are provided, they are joined as multiple elements of the path.
//
// It panics if the current working directory cannot be resolved.
func FileSource(pathElems ...string) *ModuleSource {
src := path.Join(pathElems...)
if !path.IsAbs(src) {
p, err := os.Getwd()
if err != nil {
panic(err)
}
src = path.Join(p, src)
}
return &ModuleSource{
Uri: &url.URL{
Scheme: "file",
Path: src,
},
}
}

// TextSource builds a ModuleSource whose contents are the provided text.
func TextSource(text string) *ModuleSource {
return &ModuleSource{
Expand Down
Loading