Skip to content

Commit db41be9

Browse files
authored
Feat/go proof (#208)
* Add go proof of concept * Polish docs * Speed up Julia workflows
1 parent 9042af6 commit db41be9

18 files changed

Lines changed: 1565 additions & 434 deletions

.github/workflows/go-test.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Copyright 2025 The PECOS Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
# the License. You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
9+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
# specific language governing permissions and limitations under the License.
11+
12+
name: Go test
13+
14+
env:
15+
TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes
16+
RUSTFLAGS: -C debuginfo=0
17+
RUST_BACKTRACE: 1
18+
19+
on:
20+
push:
21+
branches: [ "master", "development", "dev" ]
22+
pull_request:
23+
branches: [ "master", "development", "dev" ]
24+
workflow_dispatch:
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
cancel-in-progress: true
29+
30+
defaults:
31+
run:
32+
shell: bash
33+
34+
jobs:
35+
go-test:
36+
runs-on: ${{ matrix.os }}
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
os: [ubuntu-latest, windows-latest, macOS-latest]
41+
go-version: ["1.21", "1.22"] # Test on recent stable versions
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Set up Go ${{ matrix.go-version }}
47+
uses: actions/setup-go@v5
48+
with:
49+
go-version: ${{ matrix.go-version }}
50+
51+
- name: Set up Rust
52+
run: rustup show
53+
54+
- name: Cache Rust
55+
uses: Swatinem/rust-cache@v2
56+
with:
57+
workspaces: go/pecos-go-ffi
58+
59+
- name: Set up Visual Studio environment on Windows
60+
if: runner.os == 'Windows'
61+
uses: ilammy/msvc-dev-cmd@v1
62+
with:
63+
arch: x64
64+
65+
- name: Build Rust FFI library (Windows)
66+
if: runner.os == 'Windows'
67+
shell: pwsh
68+
run: |
69+
cd go/pecos-go-ffi
70+
cargo build --release
71+
72+
- name: Build Rust FFI library (Unix)
73+
if: runner.os != 'Windows'
74+
shell: bash
75+
run: |
76+
# On macOS, prevent Homebrew library paths from being used during linking
77+
if [[ "${{ runner.os }}" == "macOS" ]]; then
78+
# CRITICAL: Prevent Homebrew library paths from being used during linking
79+
# This fixes the "@rpath/libunwind.1.dylib" runtime error on macOS
80+
# Reference: https://github.com/rust-lang/rust/issues/135372
81+
unset LIBRARY_PATH
82+
unset LD_LIBRARY_PATH
83+
unset DYLD_LIBRARY_PATH
84+
unset DYLD_FALLBACK_LIBRARY_PATH
85+
unset PKG_CONFIG_PATH
86+
export LIBRARY_PATH=/usr/lib
87+
88+
echo "RUSTFLAGS: $RUSTFLAGS"
89+
fi
90+
91+
cd go/pecos-go-ffi
92+
cargo build --release
93+
94+
- name: Run Go tests (Unix)
95+
if: runner.os != 'Windows'
96+
run: |
97+
cd go/pecos
98+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ github.workspace }}/target/release \
99+
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${{ github.workspace }}/target/release \
100+
go test -v
101+
102+
- name: Run Go tests (Windows)
103+
if: runner.os == 'Windows'
104+
shell: pwsh
105+
run: |
106+
$env:PATH = "${{ github.workspace }}\target\release;$env:PATH"
107+
cd go/pecos
108+
go test -v
109+
110+
- name: Check Go formatting
111+
run: |
112+
cd go/pecos
113+
if [ -n "$(gofmt -l .)" ]; then
114+
echo "Formatting issues found:"
115+
gofmt -l .
116+
exit 1
117+
fi
118+
echo "All Go code is properly formatted."
119+
120+
- name: Run Go vet
121+
run: |
122+
cd go/pecos
123+
go vet ./...
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2025 The PECOS Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
# the License. You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
9+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
# specific language governing permissions and limitations under the License.
11+
12+
name: Go version consistency
13+
14+
on:
15+
push:
16+
branches: [ "master", "development", "dev" ]
17+
pull_request:
18+
branches: [ "master", "development", "dev" ]
19+
workflow_dispatch:
20+
21+
jobs:
22+
check-go-versions:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Check Go package consistency
28+
run: |
29+
echo "Checking Go package consistency..."
30+
31+
errors=0
32+
33+
# Check go.mod exists
34+
echo "=== Checking go.mod ==="
35+
if [ ! -f "go/pecos/go.mod" ]; then
36+
echo "ERROR: go/pecos/go.mod not found"
37+
errors=$((errors + 1))
38+
else
39+
echo "go.mod found"
40+
cat go/pecos/go.mod
41+
fi
42+
43+
# Check Cargo.toml for FFI
44+
echo ""
45+
echo "=== Checking pecos-go-ffi Cargo.toml ==="
46+
if [ ! -f "go/pecos-go-ffi/Cargo.toml" ]; then
47+
echo "ERROR: go/pecos-go-ffi/Cargo.toml not found"
48+
errors=$((errors + 1))
49+
else
50+
echo "Cargo.toml found"
51+
52+
# Check library name
53+
lib_name=$(grep -E '^\[lib\]' -A5 go/pecos-go-ffi/Cargo.toml | grep 'name' | sed 's/.*name = "\([^"]*\)".*/\1/')
54+
echo "Library name: $lib_name"
55+
56+
if [ "$lib_name" != "pecos_go" ]; then
57+
echo "ERROR: Library name should be 'pecos_go', got '$lib_name'"
58+
errors=$((errors + 1))
59+
fi
60+
61+
# Check crate-type includes cdylib
62+
crate_type=$(grep -E '^\[lib\]' -A5 go/pecos-go-ffi/Cargo.toml | grep 'crate-type')
63+
echo "Crate type: $crate_type"
64+
65+
if [[ "$crate_type" != *"cdylib"* ]]; then
66+
echo "ERROR: crate-type should include 'cdylib'"
67+
errors=$((errors + 1))
68+
fi
69+
fi
70+
71+
# Check module path in go.mod matches expected
72+
echo ""
73+
echo "=== Checking module path ==="
74+
module_path=$(grep '^module' go/pecos/go.mod | sed 's/module //')
75+
echo "Module path: $module_path"
76+
77+
expected_path="github.com/PECOS-packages/PECOS/go/pecos"
78+
if [ "$module_path" != "$expected_path" ]; then
79+
echo "WARNING: Module path '$module_path' doesn't match expected '$expected_path'"
80+
fi
81+
82+
# Final result
83+
echo ""
84+
echo "=== Summary ==="
85+
86+
if [ $errors -eq 0 ]; then
87+
echo "All Go package checks passed!"
88+
else
89+
echo "Found $errors issues!"
90+
exit 1
91+
fi

.github/workflows/julia-test.yml

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,41 @@ jobs:
5151
- name: Set up Rust
5252
run: rustup show
5353

54-
- name: Install LLVM 14.0.6 using pecos-llvm (Unix)
55-
if: runner.os != 'Windows'
56-
run: |
57-
echo "Installing LLVM using pecos-llvm-utils..."
58-
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
59-
60-
echo "Setting LLVM environment variables..."
61-
export PECOS_LLVM=$(cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>/dev/null)
62-
export LLVM_SYS_140_PREFIX="$PECOS_LLVM"
63-
64-
echo "PECOS_LLVM=$PECOS_LLVM" >> $GITHUB_ENV
65-
echo "LLVM_SYS_140_PREFIX=$LLVM_SYS_140_PREFIX" >> $GITHUB_ENV
66-
67-
echo "Verifying LLVM installation..."
68-
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
69-
70-
- name: Install LLVM 14.0.6 using pecos-llvm (Windows)
71-
if: runner.os == 'Windows'
72-
shell: pwsh
73-
run: |
74-
Write-Host "Installing LLVM using pecos-llvm-utils..."
75-
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
76-
77-
Write-Host "Setting LLVM environment variables..."
78-
$env:PECOS_LLVM = (cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>$null)
79-
$env:LLVM_SYS_140_PREFIX = $env:PECOS_LLVM
80-
81-
"PECOS_LLVM=$env:PECOS_LLVM" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
82-
"LLVM_SYS_140_PREFIX=$env:LLVM_SYS_140_PREFIX" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
83-
84-
Write-Host "Verifying LLVM installation..."
85-
cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
54+
# NOTE: LLVM is not currently needed for Julia FFI since we use pecos with default-features = false
55+
# Keeping this commented out in case we need to re-enable LLVM features in the future.
56+
#
57+
# - name: Install LLVM 14.0.6 using pecos-llvm (Unix)
58+
# if: runner.os != 'Windows'
59+
# run: |
60+
# echo "Installing LLVM using pecos-llvm-utils..."
61+
# cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
62+
#
63+
# echo "Setting LLVM environment variables..."
64+
# export PECOS_LLVM=$(cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>/dev/null)
65+
# export LLVM_SYS_140_PREFIX="$PECOS_LLVM"
66+
#
67+
# echo "PECOS_LLVM=$PECOS_LLVM" >> $GITHUB_ENV
68+
# echo "LLVM_SYS_140_PREFIX=$LLVM_SYS_140_PREFIX" >> $GITHUB_ENV
69+
#
70+
# echo "Verifying LLVM installation..."
71+
# cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
72+
#
73+
# - name: Install LLVM 14.0.6 using pecos-llvm (Windows)
74+
# if: runner.os == 'Windows'
75+
# shell: pwsh
76+
# run: |
77+
# Write-Host "Installing LLVM using pecos-llvm-utils..."
78+
# cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- install
79+
#
80+
# Write-Host "Setting LLVM environment variables..."
81+
# $env:PECOS_LLVM = (cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- find 2>$null)
82+
# $env:LLVM_SYS_140_PREFIX = $env:PECOS_LLVM
83+
#
84+
# "PECOS_LLVM=$env:PECOS_LLVM" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
85+
# "LLVM_SYS_140_PREFIX=$env:LLVM_SYS_140_PREFIX" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86+
#
87+
# Write-Host "Verifying LLVM installation..."
88+
# cargo run -p pecos-llvm-utils --bin pecos-llvm --release -- check
8689

8790
- name: Cache Rust
8891
uses: Swatinem/rust-cache@v2
@@ -99,7 +102,6 @@ jobs:
99102
if: runner.os == 'Windows'
100103
shell: pwsh
101104
run: |
102-
Write-Host "Building with LLVM_SYS_140_PREFIX: $env:LLVM_SYS_140_PREFIX"
103105
cd julia/pecos-julia-ffi
104106
cargo build --release
105107

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33
members = [
44
"python/pecos-rslib",
55
"julia/pecos-julia-ffi",
6+
"go/pecos-go-ffi",
67
"crates/pecos*",
78
"crates/benchmarks",
89
]

0 commit comments

Comments
 (0)