Skip to content

Commit 25eecff

Browse files
committed
WIP: Upgrade internals to C++17
1 parent 3796dd8 commit 25eecff

File tree

6 files changed

+37
-47
lines changed

6 files changed

+37
-47
lines changed

docs/install.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ deno run --allow-ffi ...
3636

3737
Ready-compiled sharp and libvips binaries are provided for use on the most common platforms:
3838

39-
* macOS x64 (>= 10.13)
39+
* macOS x64 (>= 10.15)
4040
* macOS ARM64
4141
* Linux ARM (glibc >= 2.28)
4242
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
@@ -111,7 +111,7 @@ environment variables.
111111

112112
Building from source requires:
113113

114-
* C++11 compiler
114+
* C++17 compiler
115115
* [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+
116116
* [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies
117117

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"jsdoc-to-markdown": "^9.0.4",
179179
"license-checker": "^25.0.1",
180180
"mocha": "^10.7.3",
181-
"node-addon-api": "8.1.0",
181+
"node-addon-api": "^8.2.1",
182182
"nyc": "^17.1.0",
183183
"prebuild": "^13.0.1",
184184
"semistandard": "^17.0.0",

src/binding.gyp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
'Release': {
4646
'msvs_settings': {
4747
'VCCLCompilerTool': {
48+
"AdditionalOptions": [
49+
"/std:c++17"
50+
],
4851
'ExceptionHandling': 1,
4952
'Optimization': 1,
5053
'WholeProgramOptimization': 'true'
@@ -172,6 +175,7 @@
172175
'-l:libvips-cpp.so.<(vips_version)'
173176
],
174177
'ldflags': [
178+
'-lstdc++fs',
175179
'-Wl,-s',
176180
'-Wl,--disable-new-dtags',
177181
'-Wl,-z,nodelete',
@@ -207,14 +211,14 @@
207211
}]
208212
],
209213
'cflags_cc': [
210-
'-std=c++0x',
214+
'-std=c++17',
211215
'-fexceptions',
212216
'-Wall',
213217
'-Os'
214218
],
215219
'xcode_settings': {
216-
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
217-
'MACOSX_DEPLOYMENT_TARGET': '10.13',
220+
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
221+
'MACOSX_DEPLOYMENT_TARGET': '10.15',
218222
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
219223
'GCC_ENABLE_CPP_RTTI': 'YES',
220224
'OTHER_CPLUSPLUSFLAGS': [
@@ -234,6 +238,9 @@
234238
['OS == "win"', {
235239
'msvs_settings': {
236240
'VCCLCompilerTool': {
241+
"AdditionalOptions": [
242+
"/std:c++17"
243+
],
237244
'ExceptionHandling': 1,
238245
'Optimization': 1,
239246
'WholeProgramOptimization': 'true'

src/common.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
#error "libvips version 8.16.0+ is required - please see https://sharp.pixelplumbing.com/install"
2121
#endif
2222

23-
#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
24-
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
25-
#endif
26-
27-
#if (defined(__clang__) && defined(__has_feature))
28-
#if (!__has_feature(cxx_range_for))
29-
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
23+
#if defined(__has_include)
24+
#if !__has_include(<filesystem>)
25+
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
3026
#endif
3127
#endif
3228

src/pipeline.cc

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <algorithm>
55
#include <cmath>
6+
#include <filesystem>
67
#include <map>
78
#include <memory>
89
#include <numeric>
@@ -20,17 +21,6 @@
2021
#include "operations.h"
2122
#include "pipeline.h"
2223

23-
#ifdef _WIN32
24-
#define STAT64_STRUCT __stat64
25-
#define STAT64_FUNCTION _stat64
26-
#elif defined(_LARGEFILE64_SOURCE)
27-
#define STAT64_STRUCT stat64
28-
#define STAT64_FUNCTION stat64
29-
#else
30-
#define STAT64_STRUCT stat
31-
#define STAT64_FUNCTION stat
32-
#endif
33-
3424
class PipelineWorker : public Napi::AsyncWorker {
3525
public:
3626
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
@@ -1306,10 +1296,10 @@ class PipelineWorker : public Napi::AsyncWorker {
13061296
Callback().Call(Receiver().Value(), { env.Null(), data, info });
13071297
} else {
13081298
// Add file size to info
1309-
struct STAT64_STRUCT st;
1310-
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
1311-
info.Set("size", static_cast<uint32_t>(st.st_size));
1312-
}
1299+
try {
1300+
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
1301+
info.Set("size", size);
1302+
} catch (...) {}
13131303
Callback().Call(Receiver().Value(), { env.Null(), info });
13141304
}
13151305
} else {

test/unit/tile.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ describe('Tile', function () {
483483
assert.strictEqual(2725, info.width);
484484
assert.strictEqual(2225, info.height);
485485
assert.strictEqual(3, info.channels);
486-
assert.strictEqual('number', typeof info.size);
486+
assert.strictEqual(undefined, info.size);
487487
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
488488
if (err) throw err;
489489
assert.strictEqual(true, stat.isFile());
@@ -509,7 +509,7 @@ describe('Tile', function () {
509509
assert.strictEqual(2725, info.width);
510510
assert.strictEqual(2225, info.height);
511511
assert.strictEqual(3, info.channels);
512-
assert.strictEqual('number', typeof info.size);
512+
assert.strictEqual(undefined, info.size);
513513
assertZoomifyTiles(directory, 256, 1, done);
514514
});
515515
});
@@ -530,7 +530,7 @@ describe('Tile', function () {
530530
assert.strictEqual(2725, info.width);
531531
assert.strictEqual(2225, info.height);
532532
assert.strictEqual(3, info.channels);
533-
assert.strictEqual('number', typeof info.size);
533+
assert.strictEqual(undefined, info.size);
534534
assertZoomifyTiles(directory, 256, 5, done);
535535
});
536536
});
@@ -551,7 +551,7 @@ describe('Tile', function () {
551551
assert.strictEqual(2725, info.width);
552552
assert.strictEqual(2225, info.height);
553553
assert.strictEqual(3, info.channels);
554-
assert.strictEqual('number', typeof info.size);
554+
assert.strictEqual(undefined, info.size);
555555
assertZoomifyTiles(directory, 256, 13, done);
556556
});
557557
});
@@ -575,7 +575,7 @@ describe('Tile', function () {
575575
assert.strictEqual(2048, info.width);
576576
assert.strictEqual(1536, info.height);
577577
assert.strictEqual(3, info.channels);
578-
assert.strictEqual('number', typeof info.size);
578+
assert.strictEqual(undefined, info.size);
579579
assertZoomifyTiles(directory, 256, 4, done);
580580
});
581581
});
@@ -594,7 +594,7 @@ describe('Tile', function () {
594594
assert.strictEqual(2725, info.width);
595595
assert.strictEqual(2225, info.height);
596596
assert.strictEqual(3, info.channels);
597-
assert.strictEqual('number', typeof info.size);
597+
assert.strictEqual(undefined, info.size);
598598
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
599599
if (err) throw err;
600600
assert.strictEqual(true, stat.isFile());
@@ -621,7 +621,7 @@ describe('Tile', function () {
621621
assert.strictEqual(2725, info.width);
622622
assert.strictEqual(2225, info.height);
623623
assert.strictEqual(3, info.channels);
624-
assert.strictEqual('number', typeof info.size);
624+
assert.strictEqual(undefined, info.size);
625625
const sample = path.join(directory, '0', '0', '0.jpg');
626626
sharp(sample).metadata(function (err, metadata) {
627627
if (err) throw err;
@@ -658,7 +658,7 @@ describe('Tile', function () {
658658
assert.strictEqual(2725, info.width);
659659
assert.strictEqual(2225, info.height);
660660
assert.strictEqual(3, info.channels);
661-
assert.strictEqual('number', typeof info.size);
661+
assert.strictEqual(undefined, info.size);
662662
const sample = path.join(directory, '0', '0', '0.png');
663663
sharp(sample).metadata(function (err, metadata) {
664664
if (err) throw err;
@@ -696,7 +696,7 @@ describe('Tile', function () {
696696
assert.strictEqual(2725, info.width);
697697
assert.strictEqual(2225, info.height);
698698
assert.strictEqual(3, info.channels);
699-
assert.strictEqual('number', typeof info.size);
699+
assert.strictEqual(undefined, info.size);
700700
const sample = path.join(directory, '0', '0', '0.webp');
701701
sharp(sample).metadata(function (err, metadata) {
702702
if (err) throw err;
@@ -732,8 +732,7 @@ describe('Tile', function () {
732732
assert.strictEqual(2725, info.width);
733733
assert.strictEqual(2225, info.height);
734734
assert.strictEqual(3, info.channels);
735-
assert.strictEqual('number', typeof info.size);
736-
735+
assert.strictEqual(undefined, info.size);
737736
assertGoogleTiles(directory, 256, 1, done);
738737
});
739738
});
@@ -754,8 +753,7 @@ describe('Tile', function () {
754753
assert.strictEqual(2725, info.width);
755754
assert.strictEqual(2225, info.height);
756755
assert.strictEqual(3, info.channels);
757-
assert.strictEqual('number', typeof info.size);
758-
756+
assert.strictEqual(undefined, info.size);
759757
assertGoogleTiles(directory, 256, 5, done);
760758
});
761759
});
@@ -779,8 +777,7 @@ describe('Tile', function () {
779777
assert.strictEqual(2809, info.width);
780778
assert.strictEqual(2074, info.height);
781779
assert.strictEqual(3, info.channels);
782-
assert.strictEqual('number', typeof info.size);
783-
780+
assert.strictEqual(undefined, info.size);
784781
assertGoogleTiles(directory, 256, 5, done);
785782
});
786783
});
@@ -800,7 +797,7 @@ describe('Tile', function () {
800797
assert.strictEqual(2725, info.width);
801798
assert.strictEqual(2225, info.height);
802799
assert.strictEqual(3, info.channels);
803-
assert.strictEqual('number', typeof info.size);
800+
assert.strictEqual(undefined, info.size);
804801
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
805802
});
806803
});
@@ -820,7 +817,7 @@ describe('Tile', function () {
820817
assert.strictEqual(2725, info.width);
821818
assert.strictEqual(2225, info.height);
822819
assert.strictEqual(3, info.channels);
823-
assert.strictEqual('number', typeof info.size);
820+
assert.strictEqual(undefined, info.size);
824821
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
825822
});
826823
});
@@ -842,7 +839,7 @@ describe('Tile', function () {
842839
assert.strictEqual(2725, info.width);
843840
assert.strictEqual(2225, info.height);
844841
assert.strictEqual(3, info.channels);
845-
assert.strictEqual('number', typeof info.size);
842+
assert.strictEqual(undefined, info.size);
846843
const infoJson = require(path.join(directory, 'info.json'));
847844
assert.strictEqual('http://iiif.io/api/image/2/context.json', infoJson['@context']);
848845
assert.strictEqual(`${id}/${name}`, infoJson['@id']);
@@ -872,7 +869,7 @@ describe('Tile', function () {
872869
assert.strictEqual(2725, info.width);
873870
assert.strictEqual(2225, info.height);
874871
assert.strictEqual(3, info.channels);
875-
assert.strictEqual('number', typeof info.size);
872+
assert.strictEqual(undefined, info.size);
876873
const infoJson = require(path.join(directory, 'info.json'));
877874
assert.strictEqual('http://iiif.io/api/image/3/context.json', infoJson['@context']);
878875
assert.strictEqual('ImageService3', infoJson.type);

0 commit comments

Comments
 (0)