-
Notifications
You must be signed in to change notification settings - Fork 25.2k
/
Copy pathbuild.gradle
131 lines (123 loc) · 4.34 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
apply plugin: 'c'
apply plugin: 'cpp'
var os = org.gradle.internal.os.OperatingSystem.current()
// To update this library run publish_vec_binaries.sh ( or ./gradlew vecSharedLibrary )
// Or
// For local development, build the docker image with:
// docker build --platform linux/arm64 --progress=plain --file=Dockerfile.aarch64 . (for aarch64)
// docker build --platform linux/amd64 --progress=plain --file=Dockerfile.amd64 . (for x64)
// Grab the image id from the console output, then, e.g.
// docker run 9c9f36564c148b275aeecc42749e7b4580ded79dcf51ff6ccc008c8861e7a979 > build/libs/vec/shared/$arch/libvec.so
//
// To run tests and benchmarks on a locally built libvec,
// 1. Temporarily comment out the download in libs/native/library/build.gradle
// libs "org.elasticsearch:vec:${vecVersion}@zip"
// 2. Copy your locally built libvec binary, e.g.
// cp libs/vec/native/build/libs/vec/shared/libvec.dylib libs/native/libraries/build/platform/darwin-aarch64/libvec.dylib
//
// Look at the disassemble:
// objdump --disassemble-symbols=_dot8s build/libs/vec/shared/libvec.dylib
// Note: symbol decoration may differ on Linux, i.e. the leading underscore is not present
//
// gcc -shared -fpic -o libvec.so -I src/vec/headers/ src/vec/c/vec.c -O3
group = 'org.elasticsearch'
def platformName = System.getProperty("os.arch");
model {
platforms {
aarch64 {
architecture "aarch64"
}
amd64 {
architecture "x86-64"
}
}
toolChains {
gcc(Gcc) {
target("aarch64") {
cCompiler.executable = "/usr/bin/gcc"
cCompiler.withArguments { args -> args.addAll(["-O3", "-std=c99", "-march=armv8-a"]) }
}
target("amd64") {
cCompiler.executable = "/usr/bin/gcc"
cCompiler.withArguments { args -> args.addAll(["-O3", "-std=c99", "-march=core-avx2", "-Wno-incompatible-pointer-types"]) }
cppCompiler.executable = "/usr/bin/g++"
cppCompiler.withArguments { args -> args.addAll(["-O3", "-march=core-avx2"]) }
}
}
cl(VisualCpp) {
eachPlatform { toolchain ->
def platform = toolchain.getPlatform()
if (platform.name == "x64") {
cCompiler.withArguments { args -> args.addAll(["/O2", "/LD", "-march=core-avx2"]) }
}
}
}
clang(Clang) {
target("aarch64") {
cCompiler.withArguments { args -> args.addAll(["-O3", "-std=c99", "-march=armv8-a"]) }
}
target("amd64") {
cCompiler.withArguments { args -> args.addAll(["-O3", "-std=c99", "-march=core-avx2"]) }
cppCompiler.withArguments { args -> args.addAll(["-O3", "-march=core-avx2"]) }
}
}
}
components {
vec(NativeLibrarySpec) {
targetPlatform "aarch64"
targetPlatform "amd64"
sources {
c {
source {
srcDir "src/vec/c/${platformName}/"
include "*.c"
}
exportedHeaders {
srcDir "src/vec/headers/"
}
}
cpp {
source {
srcDir "src/vec/c/${platformName}/"
include "*.cpp"
}
exportedHeaders {
srcDir "src/vec/headers/"
}
}
}
}
}
}
tasks.register('buildSharedLibrary') {
description = 'Assembles native shared library for the host architecture'
if (platformName.equals("aarch64")) {
dependsOn tasks.vecAarch64SharedLibrary
doLast {
copy {
from tasks.linkVecAarch64SharedLibrary.outputs.files.files
into layout.buildDirectory.dir('output');
duplicatesStrategy = 'INCLUDE'
}
}
} else if (platformName.equals("amd64")) {
dependsOn tasks.vecAmd64SharedLibrary
doLast {
copy {
from tasks.linkVecAmd64SharedLibrary.outputs.files.files
into layout.buildDirectory.dir('output');
duplicatesStrategy = 'INCLUDE'
}
}
} else {
throw new GradleException("Unsupported platform: " + platformName)
}
}