-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nojaf <florian.verdonck@outlook.com>
- Loading branch information
Showing
4 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_call: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
wheel: | ||
name: Build Python wheel | ||
strategy: | ||
matrix: | ||
os: ["darwin","linux", "windows"] | ||
arch: ["amd64", "arm64"] | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.22" | ||
check-latest: true | ||
cache: false | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
|
||
- name: Install mage | ||
run: go install github.com/magefile/mage@v1.15.0 | ||
|
||
- name: Run build target | ||
run: mage build ${{ matrix.os }} ${{ matrix.arch }} | ||
|
||
- name: Upload wheels artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: mlflow-go-wheels-${{ matrix.os }}-${{ matrix.arch }} | ||
path: dist/*.whl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ jobs: | |
|
||
test: | ||
uses: ./.github/workflows/test.yml | ||
|
||
build: | ||
uses: ./.github/workflows/build.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,10 @@ __pycache__/ | |
.mlflow.repo/ | ||
|
||
# JetBrains | ||
.idea | ||
.idea | ||
|
||
# Wheel | ||
build/ | ||
|
||
# virtual environment | ||
env/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//go:build mage | ||
|
||
//nolint:wrapcheck | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/magefile/mage/sh" | ||
) | ||
|
||
var errUnknownTarget = errors.New("could not determine zig target") | ||
|
||
// Helper function to determine the Zig target triple based on OS and architecture. | ||
func getTargetTriple(goos, goarch string) (string, error) { | ||
switch goos { | ||
case "linux": | ||
if goarch == "amd64" { | ||
return "x86_64-linux-gnu", nil | ||
} else if goarch == "arm64" { | ||
return "aarch64-linux-gnu", nil | ||
} | ||
case "windows": | ||
if goarch == "amd64" { | ||
return "x86_64-windows-gnu", nil | ||
} else if goarch == "arm64" { | ||
return "aarch64-windows-gnu", nil | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("%w: %s/%s", errUnknownTarget, goos, goarch) | ||
} | ||
|
||
var errUnsupportedDarwin = errors.New(`it is unsupported to build a Python wheel on Mac on a non-Mac platform`) | ||
|
||
// Build a Python wheel. | ||
func Build(goos, goarch string) error { | ||
tmp, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer os.RemoveAll(tmp) | ||
|
||
env, err := filepath.Abs(filepath.Join(tmp, ".venv")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := sh.RunV("python3", "-mvenv", env); err != nil { | ||
return err | ||
} | ||
|
||
pip := filepath.Join(env, "bin", "pip") | ||
python := filepath.Join(env, "bin", "python") | ||
|
||
if err := sh.RunV(pip, "install", "build", "ziglang"); err != nil { | ||
return err | ||
} | ||
|
||
environmentVariables := map[string]string{ | ||
"GOOS": goos, | ||
"GOARCH": goarch, | ||
} | ||
|
||
// Set Zig as the C compiler for cross-compilation | ||
// If we are on Mac and targeting Mac we don't need Zig. | ||
if goos == "darwin" { | ||
if runtime.GOOS != "darwin" { | ||
return errUnsupportedDarwin | ||
} | ||
} else { | ||
target, err := getTargetTriple(goos, goarch) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
zigCC := python + " -mziglang cc -target " + target | ||
environmentVariables["CC"] = zigCC | ||
} | ||
|
||
if err := sh.RunWithV( | ||
environmentVariables, | ||
python, "-mbuild"); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |