Skip to content

Commit 47f8a4a

Browse files
authored
Build libssh as a universal binary (#15)
* Build libssh as a universal binary * Bump version
1 parent 3e9fe1a commit 47f8a4a

4 files changed

Lines changed: 176 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ jobs:
120120
- name: Build
121121
run: ./gradlew build
122122

123-
- name: BuildArm
124-
run: ./gradlew build -Pforcealternatemacbuild
125-
126123
- uses: actions/upload-artifact@v2
127124
with:
128125
name: macOS

build.gradle

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
// Project Version
8-
ext.pub_version = "0.95-5"
8+
ext.pub_version = "0.95-6"
99

1010
static def get_platform() {
1111
def platform
@@ -25,7 +25,7 @@ static def get_platform() {
2525
} else if (OperatingSystem.current().isLinux()) {
2626
platform = "linux-${os_arch}"
2727
} else if (OperatingSystem.current().isMacOsX()) {
28-
platform = "osx-${os_arch}"
28+
platform = "osx-universal"
2929
} else {
3030
platform = "${os_name}-${os_arch}"
3131
}
@@ -43,29 +43,18 @@ static def get_platform_path(platform) {
4343
return "linux/x86"
4444
} else if (platform == "linux-x86_64") {
4545
return "linux/x86-64"
46-
} else if (platform == "osx-x86") {
47-
return "osx/x86"
48-
} else if (platform == "osx-x86_64") {
49-
return "osx/x86-64"
46+
} else if (platform == "osx-universal") {
47+
return "osx/universal"
5048
} else if (platform == "windows-x86") {
5149
return "windows/x86"
5250
} else if (platform == "windows-x86_64") {
53-
return "osx/x86-64"
54-
} else if (platform == "osx-arm64") {
55-
return "osx/arm64"
51+
return "windows/x86-64"
5652
} else {
5753
return ""
5854
}
5955
}
6056

6157
ext.platform = get_platform()
62-
if (project.hasProperty('forcealternatemacbuild')) {
63-
if (ext.platform == "osx-arm64") {
64-
ext.platform = "osx-x86_64"
65-
} else if (ext.platform == "osx-x86_64") {
66-
ext.platform = "osx-arm64"
67-
}
68-
}
6958
if (project.hasProperty('forcecrossbuild')) {
7059
ext.platform = forcecrossbuild
7160
}
@@ -79,6 +68,12 @@ ext.openssl_dir = file("openssl")
7968
ext.openssl_build_dir = file("build/$platform_path/openssl")
8069
ext.openssl_install = file("build/$platform_path/install-openssl")
8170

71+
ext.openssl_arm_build_dir = file("build/arm/openssl")
72+
ext.openssl_arm_install = file("build/arm/install-openssl")
73+
74+
ext.openssl_intel_build_dir = file("build/intel/openssl")
75+
ext.openssl_intel_install = file("build/intel/install-openssl")
76+
8277
ext.libssh_dir = file("libssh-mirror")
8378
ext.libssh_build = file("build/$platform_path/libssh")
8479

@@ -91,7 +86,11 @@ task clean {
9186
}
9287
}
9388

94-
apply from: "openssl.gradle"
89+
if (project.platform == "osx-universal") {
90+
apply from: "opensslosx.gradle"
91+
} else {
92+
apply from: "openssl.gradle"
93+
}
9594
apply from: "libssh.gradle"
9695

9796
// Outputs for publishing

libssh.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ types.each { type ->
2121
executable "cmake"
2222
args "$libssh_dir"
2323

24-
if (project.platform == "osx-arm64") {
25-
args "-DCMAKE_OSX_ARCHITECTURES=arm64", "-DCMAKE_OSX_DEPLOYMENT_TARGET=\"11.0\""
26-
environment "ARCHFLAGS", "-arch arm64"
27-
} else if (project.platform == "osx-x86_64") {
28-
args "-DCMAKE_OSX_ARCHITECTURES=x86_64", "-DCMAKE_OSX_DEPLOYMENT_TARGET=\"10.15\""
29-
environment "ARCHFLAGS", "-arch x86_64"
24+
if (project.platform == "osx-universal") {
25+
args "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64", "-DCMAKE_OSX_DEPLOYMENT_TARGET=\"11.0\""
26+
environment "ARCHFLAGS", "-arch arm64 -arch x86_64"
3027
} else if (project.platform == "linux-arm64") {
3128
if (project.hasProperty('forcecrossbuild')) {
3229
args "-DCMAKE_TOOLCHAIN_FILE=$rootDir/cmake/aarch64-bullseye-gnu.toolchain.cmake"

opensslosx.gradle

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
task prepareOpenSSLDirectories {
2+
mustRunAfter clean
3+
doLast {
4+
mkdir project.openssl_arm_build_dir
5+
mkdir project.openssl_arm_install
6+
7+
mkdir project.openssl_intel_build_dir
8+
mkdir project.openssl_intel_install
9+
}
10+
}
11+
12+
// Runs the configure step.
13+
project.tasks.create("configureOpenSSLIntel", Exec) {
14+
// OpenSSL is configured with Perl. We want to build static libraries and specify
15+
// a custom installation location.
16+
executable "perl"
17+
def configureLocation = project.file("$project.openssl_dir/Configure")
18+
args configureLocation, "no-shared", "--prefix=${project.openssl_intel_install}", "--libdir=lib"
19+
workingDir project.openssl_intel_build_dir
20+
21+
// Add the arch specifier for Windows.
22+
args "darwin64-x86_64-cc"
23+
environment "ARCHFLAGS", "-arch x86_64"
24+
25+
dependsOn prepareOpenSSLDirectories
26+
}
27+
28+
project.tasks.create("configureOpenSSLArm", Exec) {
29+
// OpenSSL is configured with Perl. We want to build static libraries and specify
30+
// a custom installation location.
31+
executable "perl"
32+
def configureLocation = project.file("$project.openssl_dir/Configure")
33+
args configureLocation, "no-shared", "--prefix=${project.openssl_arm_install}", "--libdir=lib"
34+
workingDir project.openssl_arm_build_dir
35+
36+
// Add the arch specifier for Windows.
37+
args "darwin64-arm64-cc"
38+
environment "ARCHFLAGS", "-arch arm64"
39+
40+
dependsOn prepareOpenSSLDirectories
41+
}
42+
43+
def make = "make"
44+
45+
// Runs the build step.
46+
project.tasks.create("buildOpenSSLIntel", Exec) {
47+
// Make sure that we are configured.
48+
dependsOn "configureOpenSSLIntel"
49+
50+
// OpenSSL is built with make on UNIX and nmake on Windows.
51+
executable make
52+
workingDir project.openssl_intel_build_dir
53+
54+
args "-j${project.processors}"
55+
}
56+
57+
// Runs the build step.
58+
project.tasks.create("buildOpenSSLArm", Exec) {
59+
// Make sure that we are configured.
60+
dependsOn "configureOpenSSLArm"
61+
62+
// OpenSSL is built with make on UNIX and nmake on Windows.
63+
executable make
64+
workingDir project.openssl_arm_build_dir
65+
66+
args "-j${project.processors}"
67+
}
68+
69+
// Runs the install step.
70+
project.tasks.create("installOpenSSLIntel", Exec) {
71+
// Make sure that we have built.
72+
dependsOn "buildOpenSSLIntel"
73+
74+
// OpenSSL is installed with make on UNIX and nmake on Windows.
75+
executable make
76+
args "install_sw"
77+
workingDir project.openssl_intel_build_dir
78+
79+
// UNIX supports installing with multiple workers.
80+
args "-j${project.processors}"
81+
}
82+
83+
project.tasks.create("installOpenSSLArm", Exec) {
84+
// Make sure that we have built.
85+
dependsOn "buildOpenSSLArm"
86+
87+
// OpenSSL is installed with make on UNIX and nmake on Windows.
88+
executable make
89+
args "install_sw"
90+
workingDir project.openssl_arm_build_dir
91+
92+
args "-j${project.processors}"
93+
}
94+
95+
project.tasks.create("copyOpenSSLHeaders", Copy) {
96+
dependsOn "installOpenSSLArm"
97+
dependsOn "installOpenSSLIntel"
98+
99+
from "$project.openssl_arm_install/include"
100+
into "$project.openssl_install/include"
101+
}
102+
103+
project.tasks.create("mergeCryptoBinaries", Exec) {
104+
dependsOn "installOpenSSLArm"
105+
dependsOn "installOpenSSLIntel"
106+
107+
def output = project.file("$project.openssl_install/lib/libcrypto.a")
108+
outputs.file output
109+
110+
def arm_input = project.file("$project.openssl_arm_install/lib/libcrypto.a")
111+
def intel_input = project.file("$project.openssl_intel_install/lib/libcrypto.a")
112+
113+
inputs.file arm_input
114+
inputs.file intel_input
115+
116+
executable 'lipo'
117+
118+
args = [
119+
'-create',
120+
arm_input,
121+
intel_input,
122+
'-output',
123+
output
124+
]
125+
}
126+
127+
project.tasks.create("mergeSSLBinaries", Exec) {
128+
dependsOn "installOpenSSLArm"
129+
dependsOn "installOpenSSLIntel"
130+
131+
def output = project.file("$project.openssl_install/lib/libssl.a")
132+
outputs.file output
133+
134+
def arm_input = project.file("$project.openssl_arm_install/lib/libssl.a")
135+
def intel_input = project.file("$project.openssl_intel_install/lib/libssl.a")
136+
137+
inputs.file arm_input
138+
inputs.file intel_input
139+
140+
executable 'lipo'
141+
142+
args = [
143+
'-create',
144+
arm_input,
145+
intel_input,
146+
'-output',
147+
output
148+
]
149+
}
150+
151+
// Create a "mega-task" that builds everything.
152+
project.tasks.create("openSSL") {
153+
dependsOn "copyOpenSSLHeaders"
154+
dependsOn "mergeSSLBinaries"
155+
dependsOn "mergeCryptoBinaries"
156+
outputs.dir(project.openssl_install)
157+
}

0 commit comments

Comments
 (0)