Skip to content

Commit

Permalink
Making gradle build go (#359)
Browse files Browse the repository at this point in the history
* Making gradle build go
  • Loading branch information
oxisto authored Mar 19, 2021
1 parent 699776f commit 6be3678
Show file tree
Hide file tree
Showing 19 changed files with 22 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
fi
echo "##[set-output name=version;]$VERSION"
id: determine_version
- name: Build cpgo
run: |
cd go-jni && ./build.sh && sudo cp ../libcpgo.so /usr/lib/
- name: Build ${{ steps.determine_version.outputs.version }}
run: |
if [ "$SONAR_TOKEN" != "" ]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Some languages, such as Golang are marked as experimental and depend on other na

#### Golang

In the case of Golang, the necessary native code can be found in the `go-jni` folder. In order to build it you can use the `build.sh` script, which uses `java_home` to automatically find JNI headers and stores the finished library in the cpg root folder. This currently only works for Linux and macOS.
In the case of Golang, the necessary native code can be found in the `src/main/golang` folder. Gradle should automatically find JNI headers and stores the finished library in the `src/main/golang` folder. This currently only works for Linux and macOS. In order to use it in an external project, the resulting library needs to be placed somewhere in `java.library.path`.

## Development Setup

Expand Down
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,21 @@ spotless {
googleJavaFormat()
}
}

tasks.register("compileGolang") {
doLast {
project.exec {
commandLine("./build.sh")
.setStandardOutput(System.out)
.workingDir("src/main/golang")
}
}
}

tasks.named("compileJava") {
dependsOn(":compileGolang")
}

tasks.withType<Test> {
systemProperty("java.library.path", project.projectDir.resolve("src/main/golang"))
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go-jni/build.sh → src/main/golang/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fi

export CGO_CFLAGS="-I${JAVA_HOME}/include -I/${JAVA_HOME}/include/${ARCH}"

go build -buildmode=c-shared -o ../libcpgo.${EXTENSION} lib/cpg/main.go
go build -buildmode=c-shared -o libcpgo.${EXTENSION} lib/cpg/main.go
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ class GoLanguageFrontendTest : BaseTest() {
assertEquals("true", initializer.name)

val `if` = body.statements[1] as? IfStatement

assertNotNull(`if`)
}

@Test
Expand Down

0 comments on commit 6be3678

Please sign in to comment.