Skip to content

Commit

Permalink
refactor go
Browse files Browse the repository at this point in the history
  • Loading branch information
azahnen committed Oct 13, 2024
1 parent a7b3af0 commit 721acb1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/libxtracfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ jobs:
type: macos
platform: darwin-arm64
runs-on: ${{ matrix.os.runner }}
defaults:
run:
working-directory: ./libxtracfg/c
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.2"
cache-dependency-path: xtracfg/go.sum
- uses: graalvm/setup-graalvm@v1
with:
java-version: "21"
Expand All @@ -31,21 +32,36 @@ jobs:
cache-dependency-path: |
xtracfg/*.gradle*
xtracfg/**/gradle-wrapper.properties
- name: native-image
working-directory: ./xtracfg
- name: java
working-directory: ./libxtracfg/java
run: |
./gradlew nativeCompile -PLIB=true
- name: log
run: |
ls -l ./build
- name: wrapper
ls -l ./libxtracfg/c/build
- name: c
working-directory: ./libxtracfg/c
run: |
./build.sh
- name: log2
run: |
ls -l ./build
ls -l ./libxtracfg/c/build
- name: go
working-directory: ./xtracfg
env:
CGO_FLAGS: ${{ matrix.os.type == 'macos' && '-framework CoreServices -framework Foundation' || '' }}
run: |
go build -o build/xtracfg -v
- name: log3
run: |
ls -l ./xtracfg/build
- uses: actions/upload-artifact@v4
with:
name: libxtracfg-${{ matrix.os.platform }}
path: ./libxtracfg/c/build/libxtracfg.a
retention-days: 1
- uses: actions/upload-artifact@v4
with:
name: xtracfg-${{ matrix.os.platform }}
path: ./xtracfg/build/xtracfg
retention-days: 1
2 changes: 1 addition & 1 deletion .github/workflows/xtracfg.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: xtracfg

on: [push]
on: []

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xtractl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: xtractl

on: [push]
on: []

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build
.gradle
.idea
.DS_Store
libxtracfg/go/xtracfg/libxtracfg.sha1sum
6 changes: 6 additions & 0 deletions libxtracfg/c/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ echo "lib"
clang -c -Wall -I./ -I$JAVA_HOME/include -I$JAVA_HOME/include/${PLATFORM} -o libxtracfg.o ../wrapper/libxtracfg.c
cp libxtracfgjni.a libxtracfg.a
ar -rv libxtracfg.a libxtracfg.o
if [ "$PLATFORM" = "darwin" ]; then
shasum libxtracfg.a > libxtracfg.sha1sum
else
sha1sum libxtracfg.a > libxtracfg.sha1sum
fi
cp libxtracfg.sha1sum ../../go/xtracfg/

echo "test"

Expand Down
9 changes: 9 additions & 0 deletions libxtracfg/c/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

#include "../include/libxtracfg.h"

void progress (const char* msg) {
printf("%s\n", msg);
}

int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <json command>\n", argv[0]);
fprintf(stderr, "Example: %s '{\"command\": \"info\", \"source\": \"/Users/az/development/configs-ldproxy/embed\"}'\n", argv[0]);
exit(1);
}

xtracfg_init();
xtracfg_progress_subscribe(progress);

int err = 0;
char *result = xtracfg_execute( argv[1], &err);

xtracfg_cleanup();

if (err > 0) {
fprintf(stderr, "Unexpected error: %s\n", result);
free(result);
Expand Down
8 changes: 7 additions & 1 deletion libxtracfg/go/xtracfg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xtracfg

/*
#cgo CFLAGS: -I ../../c/include
#cgo LDFLAGS: -L../../c/build -lxtracfg -framework CoreServices -framework Foundation
#cgo LDFLAGS: -L../../c/build -lxtracfg
#include <stdlib.h>
#include "libxtracfg.h"
Expand All @@ -12,6 +12,7 @@ void progress(char *msg);
import "C"

import (
_ "embed"
"encoding/json"
"fmt"
"path/filepath"
Expand All @@ -20,6 +21,11 @@ import (
"unsafe"
)

// needed to trigger a rebuild when libxtracfg.a changes
//
//go:embed libxtracfg.sha1sum
var res string

// Store is
type Store struct {
source *string
Expand Down

0 comments on commit 721acb1

Please sign in to comment.