Skip to content

Commit

Permalink
WIP: Upgrade internals to C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jan 20, 2024
1 parent bd4f1ab commit 1d0f579
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 46 deletions.
4 changes: 2 additions & 2 deletions docs/install.md
Expand Up @@ -41,7 +41,7 @@ deno run --allow-ffi ...

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

* macOS x64 (>= 10.13)
* macOS x64 (>= 10.15)
* macOS ARM64
* Linux ARM (glibc >= 2.28)
* Linux ARM64 (glibc >= 2.26, musl >= 1.2.2)
Expand Down Expand Up @@ -108,7 +108,7 @@ This module will be compiled from source at `npm install` time when:

Building from source requires:

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

Expand Down
10 changes: 7 additions & 3 deletions src/binding.gyp
Expand Up @@ -172,6 +172,7 @@
'-l:libvips-cpp.so.42'
],
'ldflags': [
'-lstdc++fs',
'-Wl,-s',
'-Wl,--disable-new-dtags',
'-Wl,-z,nodelete',
Expand Down Expand Up @@ -207,14 +208,14 @@
}]
],
'cflags_cc': [
'-std=c++0x',
'-std=c++17',
'-fexceptions',
'-Wall',
'-Os'
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'MACOSX_DEPLOYMENT_TARGET': '10.13',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
'MACOSX_DEPLOYMENT_TARGET': '10.15',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
'OTHER_CPLUSPLUSFLAGS': [
Expand All @@ -234,6 +235,9 @@
['OS == "win"', {
'msvs_settings': {
'VCCLCompilerTool': {
"AdditionalOptions": [
"/std:c++17"
],
'ExceptionHandling': 1,
'Optimization': 1,
'WholeProgramOptimization': 'true'
Expand Down
10 changes: 3 additions & 7 deletions src/common.h
Expand Up @@ -20,13 +20,9 @@
#error "libvips version 8.15.1+ is required - please see https://sharp.pixelplumbing.com/install"
#endif

#if ((!defined(__clang__)) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)))
#error "GCC version 4.6+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#endif

#if (defined(__clang__) && defined(__has_feature))
#if (!__has_feature(cxx_range_for))
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
#if defined(__has_include)
#if !__has_include(<filesystem>)
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
#endif
#endif

Expand Down
20 changes: 5 additions & 15 deletions src/pipeline.cc
Expand Up @@ -3,6 +3,7 @@

#include <algorithm>
#include <cmath>
#include <filesystem>
#include <map>
#include <memory>
#include <numeric>
Expand All @@ -20,17 +21,6 @@
#include "operations.h"
#include "pipeline.h"

#ifdef _WIN32
#define STAT64_STRUCT __stat64
#define STAT64_FUNCTION _stat64
#elif defined(_LARGEFILE64_SOURCE)
#define STAT64_STRUCT stat64
#define STAT64_FUNCTION stat64
#else
#define STAT64_STRUCT stat
#define STAT64_FUNCTION stat
#endif

class PipelineWorker : public Napi::AsyncWorker {
public:
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
Expand Down Expand Up @@ -1291,10 +1281,10 @@ class PipelineWorker : public Napi::AsyncWorker {
Callback().Call(Receiver().Value(), { env.Null(), data, info });
} else {
// Add file size to info
struct STAT64_STRUCT st;
if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
info.Set("size", static_cast<uint32_t>(st.st_size));
}
try {
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut.data()));
info.Set("size", size);
} catch (...) {}
Callback().Call(Receiver().Value(), { env.Null(), info });
}
} else {
Expand Down
35 changes: 16 additions & 19 deletions test/unit/tile.js
Expand Up @@ -485,7 +485,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
Expand All @@ -511,7 +511,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
assertZoomifyTiles(directory, 256, 1, done);
});
});
Expand All @@ -532,7 +532,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
assertZoomifyTiles(directory, 256, 5, done);
});
});
Expand All @@ -553,7 +553,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
assertZoomifyTiles(directory, 256, 13, done);
});
});
Expand All @@ -577,7 +577,7 @@ describe('Tile', function () {
assert.strictEqual(2048, info.width);
assert.strictEqual(1536, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
assertZoomifyTiles(directory, 256, 4, done);
});
});
Expand All @@ -596,7 +596,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
Expand All @@ -623,7 +623,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
const sample = path.join(directory, '0', '0', '0.jpg');
sharp(sample).metadata(function (err, metadata) {
if (err) throw err;
Expand Down Expand Up @@ -660,7 +660,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
const sample = path.join(directory, '0', '0', '0.png');
sharp(sample).metadata(function (err, metadata) {
if (err) throw err;
Expand Down Expand Up @@ -698,7 +698,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
const sample = path.join(directory, '0', '0', '0.webp');
sharp(sample).metadata(function (err, metadata) {
if (err) throw err;
Expand Down Expand Up @@ -734,8 +734,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);

assert.strictEqual(undefined, info.size);
assertGoogleTiles(directory, 256, 1, done);
});
});
Expand All @@ -756,8 +755,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);

assert.strictEqual(undefined, info.size);
assertGoogleTiles(directory, 256, 5, done);
});
});
Expand All @@ -781,8 +779,7 @@ describe('Tile', function () {
assert.strictEqual(2809, info.width);
assert.strictEqual(2074, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);

assert.strictEqual(undefined, info.size);
assertGoogleTiles(directory, 256, 5, done);
});
});
Expand All @@ -802,7 +799,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
});
});
Expand All @@ -822,7 +819,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
fixtures.assertSimilar(fixtures.expected('tile_centered.jpg'), fs.readFileSync(path.join(directory, '0', '0', '0.jpg')), done);
});
});
Expand All @@ -844,7 +841,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
const infoJson = require(path.join(directory, 'info.json'));
assert.strictEqual('http://iiif.io/api/image/2/context.json', infoJson['@context']);
assert.strictEqual(`${id}/${name}`, infoJson['@id']);
Expand Down Expand Up @@ -874,7 +871,7 @@ describe('Tile', function () {
assert.strictEqual(2725, info.width);
assert.strictEqual(2225, info.height);
assert.strictEqual(3, info.channels);
assert.strictEqual('number', typeof info.size);
assert.strictEqual(undefined, info.size);
const infoJson = require(path.join(directory, 'info.json'));
assert.strictEqual('http://iiif.io/api/image/3/context.json', infoJson['@context']);
assert.strictEqual('ImageService3', infoJson.type);
Expand Down

0 comments on commit 1d0f579

Please sign in to comment.