Skip to content

Commit ce5081e

Browse files
committed
Fix the assembler gradle task
1 parent 21f3287 commit ce5081e

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

ddprof-lib/build.gradle

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,18 @@ tasks.whenTaskAdded { task ->
516516
onlyIf {
517517
config.active
518518
}
519+
519520
group = 'build'
520521
description = "Link the ${config.name} build of the library"
521522
source = fileTree("$buildDir/obj/main/${config.name}")
523+
source.from(file("${projectDir}/build/obj/main/asm/assembly.o"))
524+
522525
linkedFile = file("$buildDir/lib/main/${config.name}/${osIdentifier()}/${archIdentifier()}/libjavaProfiler.${os().isLinux() ? 'so' : 'dylib'}")
523526
def compileTask = tasks.findByName("compileLib${config.name.capitalize()}".toString())
524527
if (compileTask != null) {
525528
dependsOn compileTask
526529
}
530+
def asmTask = tasks.findByName("asm")
527531
dependsOn asmTask
528532
linkerArgs.addAll(config.linkerArgs)
529533
toolChain = task.toolChain
@@ -605,22 +609,43 @@ tasks.register('javadocJar', Jar) {
605609
from javadoc.destinationDir
606610
}
607611

608-
tasks.register('asmTask', Exec) {
609-
String reportedArch = System.getProperty('os.arch')
610-
String arch
611-
if (reportedArch == 'x86_64') {
612+
tasks.register('asm', Exec) {
613+
group = 'build'
614+
615+
def arch
616+
if (archIdentifier() == 'x64') {
612617
arch = '-D__x86_64__'
613618
} else {
614619
arch = '-D__aarch64__'
615620
}
616621

617-
String os
622+
def os
618623
if (osIdentifier() == 'macos') {
619624
os = '-D__APPLE__'
620625
} else {
621626
os = '-D__LINUX__'
622627
}
623-
commandLine 'gcc', arch, os, 'src/main/assembler/safefetch.S', '-c', 'safefetch.o'
628+
def asmDir = file("${projectDir}/src/main/assembler")
629+
if (!asmDir.exists()) {
630+
// no assembler files found, skipping
631+
return;
632+
}
633+
634+
doLast {
635+
// Ensure the output directory exists
636+
file("${projectDir}/build/obj/main/asm").mkdirs()
637+
}
638+
639+
// collect all assembler files and compile them
640+
workingDir asmDir
641+
inputs.files fileTree("${projectDir}/src/main/assembler") {
642+
include '**/*.S'
643+
}
644+
def asmFiles = inputs.files.collect { it.absolutePath }
645+
outputs.dir "${projectDir}/build/obj/main/asm"
646+
// use gcc to compile assembler files
647+
commandLine 'gcc', arch, os, '-c', '-x', 'assembler-with-cpp',
648+
*asmFiles, '-o', "${projectDir}/build/obj/main/asm/assembly.o"
624649
}
625650

626651
tasks.register('scanBuild', Exec) {

ddprof-lib/gtest/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ tasks.whenTaskAdded { task ->
154154
group = 'verification'
155155
description = "Run all Google Tests for the ${config.name} build of the library"
156156
}
157-
project(':ddprof-lib').file("src/test/cpp/").eachFile {
157+
def libProject = project(':ddprof-lib')
158+
def asmTask = libProject.tasks.findByName("asm")
159+
160+
libProject.file("src/test/cpp/").eachFile {
158161

159162
def testFile = it
160163
def testName = it.name.substring(0, it.name.lastIndexOf('.'))
@@ -167,6 +170,7 @@ tasks.whenTaskAdded { task ->
167170
group = 'build'
168171
description = "Link the Google Test for the ${config.name} build of the library"
169172
source = fileTree("$buildDir/obj/gtest/${config.name}/${testName}")
173+
source.from(file("${rootDir}/ddprof-lib/build/obj/main/asm/assembly.o"))
170174
linkedFile = binary
171175
if (config.name != 'release') {
172176
// linking the gtests using the minimizing release flags is making gtest unhappy
@@ -183,6 +187,7 @@ tasks.whenTaskAdded { task ->
183187
libs = task.libs
184188
inputs.files source
185189
outputs.file linkedFile
190+
dependsOn asmTask
186191
}
187192
def gtestExecuteTask = tasks.register("gtest${config.name.capitalize()}_${testName}", Exec) {
188193
onlyIf {

0 commit comments

Comments
 (0)