Skip to content

Commit 1e94a66

Browse files
committed
Added build commands for openssl
1 parent 3b2e449 commit 1e94a66

File tree

8 files changed

+227
-146
lines changed

8 files changed

+227
-146
lines changed

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "openssl",
9+
"request": "launch",
10+
"type": "dart"
11+
},
12+
{
13+
"name": "Debug Build Hook",
14+
"type": "dart",
15+
"request": "launch",
16+
"program": "hook/build.dart",
17+
"args": [
18+
"--config",
19+
".dart_tool/hooks_runner/openssl/9fb02c5622aea66c3a53a942a16bf409/input.json"
20+
]
21+
}
22+
]
23+
}

hook/build.dart

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import 'dart:io';
2+
3+
import 'package:code_assets/code_assets.dart';
4+
import 'package:hooks/hooks.dart';
5+
6+
void main(List<String> args) async {
7+
const version = '3.5.4';
8+
const sourceCodeUrl = 'https://github.com/openssl/openssl/releases/download/openssl-$version/openssl-$version.tar.gz';
9+
const openSslDirName = 'openssl-$version';
10+
11+
await build(args, (input, output) async {
12+
if (input.config.buildCodeAssets) {
13+
final workDir = Directory(input.outputDirectory.path);
14+
// download source code from openssl
15+
await runProcess('curl', ['-L', sourceCodeUrl, '-o', '$openSslDirName.tar.gz'], workingDirectory: workDir);
16+
17+
// unzip source code
18+
await runProcess('tar', ['-xzf', '$openSslDirName.tar.gz'], workingDirectory: workDir);
19+
20+
final openSslDir = Directory(workDir.uri.resolve(openSslDirName).path);
21+
22+
// build source code, depends on the OS we are running on
23+
// Read https://github.com/openssl/openssl/blob/openssl-3.5.4/INSTALL.md#building-openssl
24+
final configName = resolveConfigName(input.config.code.targetOS, input.config.code.targetArchitecture);
25+
switch (OS.current) {
26+
case OS.windows:
27+
// run ./Configure with the target OS and architecture
28+
await runProcess('perl', [
29+
'Configure',
30+
configName,
31+
'no-unit-test',
32+
'no-asm',
33+
'no-makedepend',
34+
// needed to build using multiple threads on Windows
35+
'/FS',
36+
], workingDirectory: openSslDir);
37+
38+
// run jom to build the library
39+
await runProcess('jom', [
40+
// TODO: don't know if this is needed
41+
// 'build_sw',
42+
'-j',
43+
'${Platform.numberOfProcessors}',
44+
'-c',
45+
'user.openssl:windows_use_jom=True',
46+
], workingDirectory: openSslDir);
47+
break;
48+
case OS.macOS:
49+
case OS.linux:
50+
// run ./Configure with the target OS and architecture
51+
await runProcess('./Configure', [
52+
configName,
53+
'no-unit-test',
54+
'no-asm',
55+
'no-makedepend',
56+
], workingDirectory: openSslDir);
57+
58+
// run make
59+
await runProcess('make', ['-j', '${Platform.numberOfProcessors}'], workingDirectory: openSslDir);
60+
break;
61+
}
62+
}
63+
});
64+
}
65+
66+
String resolveConfigName(OS os, Architecture architecture) {
67+
return switch ((os, architecture)) {
68+
(OS.android, Architecture.arm) => 'android-arm',
69+
(OS.android, Architecture.arm64) => 'android-arm64',
70+
(OS.android, Architecture.ia32) => 'android-x86',
71+
(OS.android, Architecture.x64) => 'android-x86_64',
72+
(OS.android, Architecture.riscv64) => 'android-riscv64',
73+
74+
(OS.iOS, Architecture.arm) => 'ios-xcrun',
75+
(OS.iOS, Architecture.arm64) => 'ios64-xcrun',
76+
(OS.iOS, Architecture.ia32) => 'iossimulator-i386-xcrun',
77+
(OS.iOS, Architecture.x64) => 'iossimulator-x86_64-xcrun',
78+
79+
(OS.macOS, Architecture.arm64) => 'darwin64-arm64',
80+
(OS.macOS, Architecture.x64) => 'darwin64-x86_64',
81+
(OS.macOS, Architecture.ia32) => 'darwin-i386',
82+
83+
(OS.linux, Architecture.arm) => 'linux-armv4',
84+
(OS.linux, Architecture.arm64) => 'linux-aarch64',
85+
(OS.linux, Architecture.ia32) => 'linux-x86',
86+
(OS.linux, Architecture.x64) => 'linux-x86_64',
87+
(OS.linux, Architecture.riscv32) => 'linux32-riscv32',
88+
(OS.linux, Architecture.riscv64) => 'linux64-riscv64',
89+
90+
(OS.windows, Architecture.arm) => 'VC-WIN32-ARM',
91+
(OS.windows, Architecture.arm64) => 'VC-WIN64-ARM',
92+
(OS.windows, Architecture.ia32) => 'VC-WIN32',
93+
(OS.windows, Architecture.x64) => 'VC-WIN64A',
94+
95+
_ => throw UnsupportedError('Unsupported target combination: ${os.name}-${architecture.name}'),
96+
};
97+
}
98+
99+
Future<void> runProcess(String executable, List<String> arguments, {Directory? workingDirectory}) async {
100+
print('----------');
101+
print('Running `$executable $arguments` in $workingDirectory');
102+
final processResult = await Process.run(executable, arguments, workingDirectory: workingDirectory?.path);
103+
print('stdout:');
104+
print(processResult.stdout);
105+
if ((processResult.stderr as String).isNotEmpty) {
106+
print('stderr:');
107+
print(processResult.stderr);
108+
}
109+
if (processResult.exitCode != 0) {
110+
throw ProcessException(executable, arguments, '', processResult.exitCode);
111+
}
112+
print('==========');
113+
}

hooks/build.dart

Lines changed: 0 additions & 31 deletions
This file was deleted.

lib/openssl.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// This package provides a Dart raw wrapper for the OpenSSL library.
2+
/// It means that it replicates the exact same methods and names that are available in the OpenSSL library.
3+
/// Making you responsible to manage the memory allocation and studying how to use from official OpenSSL documentation.
4+
library;
5+
6+
export 'src/third_party/openssl.g.dart';

lib/openssl_dart.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/src/openssl_dart_base.dart

Lines changed: 0 additions & 101 deletions
This file was deleted.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: openssl_dart
1+
name: openssl
22
description: A starting point for Dart libraries or applications.
33
version: 1.0.0
44
# repository: https://github.com/my_org/my_repo

0 commit comments

Comments
 (0)