Skip to content

Commit a247669

Browse files
authored
Add sodium extension support for Windows (#651)
* Add sodium extension support for Windows * cs-fix
1 parent 99be7b0 commit a247669

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed

config/ext.json

-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@
674674
},
675675
"sodium": {
676676
"support": {
677-
"Windows": "wip",
678677
"BSD": "wip"
679678
},
680679
"type": "builtin",

config/lib.json

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@
442442
"source": "libsodium",
443443
"static-libs-unix": [
444444
"libsodium.a"
445+
],
446+
"static-libs-windows": [
447+
"libsodium.lib"
445448
]
446449
},
447450
"libssh2": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\windows\library;
6+
7+
use SPC\builder\windows\SystemUtil;
8+
use SPC\exception\RuntimeException;
9+
use SPC\store\FileSystem;
10+
11+
class libsodium extends WindowsLibraryBase
12+
{
13+
public const NAME = 'libsodium';
14+
15+
protected function build()
16+
{
17+
FileSystem::replaceFileStr($this->source_dir . '\src\libsodium\include\sodium\export.h', '#ifdef SODIUM_STATIC', '#if 1');
18+
$vs_ver_dir = match (SystemUtil::findVisualStudio()['version']) {
19+
'vs17' => '\vs2022',
20+
'vs16' => '\vs2019',
21+
default => throw new RuntimeException('Current VS version is not supported yet!'),
22+
};
23+
24+
// start build
25+
cmd()->cd($this->source_dir . '\builds\msvc\\' . $vs_ver_dir)
26+
->execWithWrapper(
27+
$this->builder->makeSimpleWrapper('msbuild'),
28+
'libsodium.sln /t:Rebuild /p:Configuration=StaticRelease /p:Platform=x64 /p:PreprocessorDefinitions="SODIUM_STATIC=1"'
29+
);
30+
FileSystem::createDir(BUILD_LIB_PATH);
31+
FileSystem::createDir(BUILD_INCLUDE_PATH);
32+
33+
// copy include
34+
FileSystem::copyDir($this->source_dir . '\src\libsodium\include\sodium', BUILD_INCLUDE_PATH . '\sodium');
35+
copy($this->source_dir . '\src\libsodium\include\sodium.h', BUILD_INCLUDE_PATH . '\sodium.h');
36+
// copy lib
37+
$ls = FileSystem::scanDirFiles($this->source_dir . '\bin');
38+
$find = false;
39+
foreach ($ls as $file) {
40+
if (str_ends_with($file, 'libsodium.lib')) {
41+
copy($file, BUILD_LIB_PATH . '\libsodium.lib');
42+
$find = true;
43+
}
44+
if (str_ends_with($file, 'libsodium.pdb')) {
45+
copy($file, BUILD_LIB_PATH . '\libsodium.pdb');
46+
}
47+
}
48+
if (!$find) {
49+
throw new RuntimeException('libsodium.lib not found');
50+
}
51+
}
52+
}

src/globals/test-extensions.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
// test php version
1515
$test_php_version = [
1616
'8.1',
17-
// '8.2',
18-
// '8.3',
17+
'8.2',
18+
'8.3',
1919
'8.4',
2020
];
2121

2222
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
2323
$test_os = [
24-
// 'macos-13',
25-
// 'macos-14',
26-
// 'ubuntu-latest',
27-
'windows-2019',
28-
'windows-latest',
24+
'macos-13',
25+
'macos-14',
26+
'ubuntu-latest',
27+
// 'windows-latest',
2928
];
3029

3130
// whether enable thread safe
@@ -42,13 +41,13 @@
4241
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
4342
$extensions = match (PHP_OS_FAMILY) {
4443
'Linux', 'Darwin' => 'gettext',
45-
'Windows' => 'gd',
44+
'Windows' => 'bcmath',
4645
};
4746

4847
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
4948
$with_libs = match (PHP_OS_FAMILY) {
5049
'Linux', 'Darwin' => '',
51-
'Windows' => 'libavif',
50+
'Windows' => '',
5251
};
5352

5453
// Please change your test base combination. We recommend testing with `common`.

0 commit comments

Comments
 (0)