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

fix pkg-config generation on windows #30

Closed
wants to merge 7 commits into from
Closed
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
36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Install embedme
run: npm install -g embedme

- name: Verify README.md embedded code
run: npx embedme --verify README.md

- name: Check formatting
run: |
if [ -n "$(go fmt ./...)" ]; then
echo "Some files are not properly formatted. Please run 'go fmt ./...'"
exit 1
fi
67 changes: 10 additions & 57 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,20 @@ on:
branches: [ "main" ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install embedme
run: npm install -g embedme

- name: Verify README.md embedded code
run: npx embedme --verify README.md

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Check formatting
run: |
if [ -n "$(go fmt ./...)" ]; then
echo "Some files are not properly formatted. Please run 'go fmt ./...'"
exit 1
fi

build:
continue-on-error: true
strategy:
fail-fast: false
matrix:
sys:
- {os: macos-latest, shell: bash}
- {os: ubuntu-24.04, shell: bash}
- {os: windows-latest, shell: bash}
os:
- macos-latest
- ubuntu-24.04
- windows-latest
defaults:
run:
shell: ${{ matrix.sys.shell }}
runs-on: ${{matrix.sys.os}}
shell: bash
runs-on: ${{matrix.os}}
steps:
# - uses: msys2/setup-msys2@v2
# if: matrix.sys.os == 'windows-latest'
# with:
# update: true
# install: >-
# curl
# git
# pkg-config

- uses: actions/checkout@v4

- name: Set up Go
Expand All @@ -72,15 +35,15 @@ jobs:
with:
python-version: '3.13'
update-environment: true

- name: Generate Python pkg-config for windows (patch)
if: matrix.sys.os == 'windows-latest'
if: matrix.os == 'windows-latest'
run: |
mkdir -p $PKG_CONFIG_PATH
cp .github/assets/python3-embed.pc $PKG_CONFIG_PATH/

- name: Install tiny-pkg-config for windows (patch)
if: matrix.sys.os == 'windows-latest'
if: matrix.os == 'windows-latest'
run: |
set -x
curl -L https://github.com/cpunion/tiny-pkg-config/releases/download/v0.2.0/tiny-pkg-config_Windows_x86_64.zip -o /tmp/tiny-pkg-config.zip
Expand All @@ -96,16 +59,6 @@ jobs:

- name: Test with coverage
run: go test -coverprofile=coverage.txt -covermode=atomic ./...

- name: Test gopy
run: |
set -x
gopy init $HOME/foo
cd $HOME/foo
gopy build -v .
export GP_INJECT_DEBUG=1
gopy run -v .
gopy install -v .

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
102 changes: 102 additions & 0 deletions .github/workflows/gopy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Gopy

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install gopy
run: go install ./cmd/gopy

- name: Test init project
run: gopy init ../foo

- name: Test build project
env:
GP_INJECT_DEBUG: "1"
run: |
Set-PSDebug -Trace 2
cd ../foo
dir .deps/python/lib/pkgconfig
gopy build -o foo.exe .
gopy exec dir
$env:PATH=".deps/python;$env:PATH"
$env:PATH
./foo.exe

- name: Test run project
env:
GP_INJECT_DEBUG: "1"
run: |
cd ../foo
gopy run -v .

- name: Test install project
run: |
cd ../foo
gopy install -v .

test:
continue-on-error: true
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-24.04
defaults:
run:
shell: bash
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install gopy
run: go install ./cmd/gopy

- name: Test init project
run: gopy init $HOME/foo

- name: Test build project
env:
GP_INJECT_DEBUG: "1"
run: |
set -x
cd $HOME/foo
gopy exec env
ls $HOME/foo/.deps/python/lib/pkgconfig
gopy build -o foo .
gopy exec ls -lh
./foo

- name: Test run project
env:
GP_INJECT_DEBUG: "1"
run: |
cd $HOME/foo
gopy run -v .

- name: Test install project
run: |
cd $HOME/foo
gopy install -v .
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}(),
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if err := rungo.RunGoCommand("build", args); err != nil {
if err := rungo.RunCommand("go", append([]string{"build"}, args...)); err != nil {

Check warning on line 28 in cmd/build.go

View check run for this annotation

Codecov / codecov/patch

cmd/build.go#L28

Added line #L28 was not covered by tests
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"os"

"github.com/cpunion/go-python/cmd/internal/rungo"
"github.com/spf13/cobra"
)

// execCmd represents the run command
var execCmd = &cobra.Command{
Use: "exec [flags] [arguments...]",
Short: "Exec command with the Go and Python environment properly configured",
Long: "Exec executes a command with the Go and Python environment properly configured.",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
return
}
if err := rungo.RunCommand(args[0], args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}

Check warning on line 28 in cmd/exec.go

View check run for this annotation

Codecov / codecov/patch

cmd/exec.go#L20-L28

Added lines #L20 - L28 were not covered by tests
},
}

func init() {
rootCmd.AddCommand(execCmd)

Check warning on line 33 in cmd/exec.go

View check run for this annotation

Codecov / codecov/patch

cmd/exec.go#L32-L33

Added lines #L32 - L33 were not covered by tests
}
2 changes: 1 addition & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}(),
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if err := rungo.RunGoCommand("install", args); err != nil {
if err := rungo.RunCommand("go", append([]string{"install"}, args...)); err != nil {

Check warning on line 28 in cmd/install.go

View check run for this annotation

Codecov / codecov/patch

cmd/install.go#L28

Added line #L28 was not covered by tests
fmt.Println("Error:", err)
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/internal/create/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
func main() {
Initialize()
defer Finalize()
println("Hello, World!")

Check warning on line 10 in cmd/internal/create/templates/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/create/templates/main.go#L10

Added line #L10 was not covered by tests
}
13 changes: 0 additions & 13 deletions cmd/internal/install/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ func Dependencies(projectPath string, goVersion, tinyPkgConfigVersion, pyVersion
return err
}

if runtime.GOOS == "windows" {
pythonPath := env.GetPythonRoot(projectPath)
pkgConfigDir := env.GetPythonPkgConfigDir(projectPath)
if err := generatePkgConfig(pythonPath, pkgConfigDir); err != nil {
return err
}
}

// Update pkg-config files
if err := updatePkgConfig(projectPath); err != nil {
return err
}

return nil
}

Expand Down
Loading
Loading