Skip to content

Commit e1b5dee

Browse files
committed
added sharp example, improved all examples and added readmes
1 parent 036c2f8 commit e1b5dee

File tree

20 files changed

+899
-20
lines changed

20 files changed

+899
-20
lines changed

examples/express-app/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ in rec {
1313
chmod +x $out/bin/express-app
1414
'';
1515
shell = mkShell {
16+
buildInputs = [app];
1617
shellHook = ''
17-
ln -sf ${node_modules} node_modules
18+
ln -sfn ${node_modules} node_modules
1819
'';
1920
};
2021
}

examples/express-app/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ app.get("/", (req, res) => {
55
res.end("hello world");
66
});
77
app.listen(8080);
8+
console.log("visit http://localhost:8080");

examples/express-app/readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#express-app example
2+
3+
## using
4+
5+
1. run `nix-shell`
6+
1. the `express` package is now installed in the `node_modules` directory. You can import and use it in any file.
7+
1. run `express-app` to start the example app
8+
9+
## notes
10+
11+
In this pure js modules were used. It's the simplest form of using node_modules.nix

examples/sass-compile-app/default.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{pkgs?import<nixpkgs> {}}:with pkgs;
2+
let
3+
buildNodeModules = callPackage ../../buildNodeModules.nix {};
4+
in rec {
5+
node_modules = buildNodeModules {directory = ./.;buildInputs=[python];};
6+
app = runCommand "compile-sass" {buildInputs=[nodejs];} ''
7+
mkdir -p $out/bin
8+
ln -s ${node_modules}/.bin/node-sass $out/bin/compile-sass
9+
'';
10+
shell = mkShell {
11+
buildInputs = [app];
12+
shellHook = ''
13+
export PATH=$PATH:$PWD/node_modules/.bin
14+
ln -sfn ${node_modules} node_modules
15+
'';
16+
};
17+
}

examples/sass-lib/package-lock.json renamed to examples/sass-compile-app/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sass-lib/package.json renamed to examples/sass-compile-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "sass-lib",
2+
"name": "sass-compile-app",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",

examples/sass-compile-app/readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#sass-compile-app example
2+
3+
## using
4+
5+
1. run `nix-shell`
6+
1. the `node-sass` package is now installed in the `node_modules` directory. You can import and use it in any file.
7+
1. the `node-sass` command that comes with the package is also availabe in the shell
8+
1. run `compile-sass style.scss > style.css` to start the example app
9+
10+
## notes
11+
12+
In this example, the `node-sass` package has native dependencies. Fortunately, it builds from source without any patching.
File renamed without changes.

examples/sass-lib/default.nix

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
'targets': [{
3+
'target_name': 'libvips-cpp',
4+
'conditions': [
5+
['OS == "win"', {
6+
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
7+
'type': 'shared_library',
8+
'defines': [
9+
'VIPS_CPLUSPLUS_EXPORTS',
10+
'_ALLOW_KEYWORD_MACROS'
11+
],
12+
'sources': [
13+
'src/libvips/cplusplus/VError.cpp',
14+
'src/libvips/cplusplus/VConnection.cpp',
15+
'src/libvips/cplusplus/VInterpolate.cpp',
16+
'src/libvips/cplusplus/VImage.cpp'
17+
],
18+
'include_dirs': [
19+
'vendor/include',
20+
'vendor/include/glib-2.0',
21+
'vendor/lib/glib-2.0/include'
22+
],
23+
'libraries': [
24+
'../vendor/lib/libvips.lib',
25+
'../vendor/lib/libglib-2.0.lib',
26+
'../vendor/lib/libgobject-2.0.lib'
27+
],
28+
'configurations': {
29+
'Release': {
30+
'msvs_settings': {
31+
'VCCLCompilerTool': {
32+
'ExceptionHandling': 1,
33+
'WholeProgramOptimization': 'true'
34+
},
35+
'VCLibrarianTool': {
36+
'AdditionalOptions': [
37+
'/LTCG:INCREMENTAL'
38+
]
39+
},
40+
'VCLinkerTool': {
41+
'ImageHasSafeExceptionHandlers': 'false',
42+
'OptimizeReferences': 2,
43+
'EnableCOMDATFolding': 2,
44+
'LinkIncremental': 1,
45+
'AdditionalOptions': [
46+
'/LTCG:INCREMENTAL'
47+
]
48+
}
49+
},
50+
'msvs_disabled_warnings': [
51+
4275
52+
]
53+
}
54+
}
55+
}, {
56+
# Ignore this target for non-Windows
57+
'type': 'none'
58+
}]
59+
]
60+
}, {
61+
'target_name': 'sharp',
62+
'defines': [
63+
'NAPI_VERSION=3'
64+
],
65+
'dependencies': [
66+
'<!(node -p "require(\'node-addon-api\').gyp")',
67+
'libvips-cpp'
68+
],
69+
'variables': {
70+
'runtime_link%': 'shared',
71+
'pkg_config_path': '<!(node -e "console.log(require(\'./lib/libvips\').pkgConfigPath())")',
72+
'use_global_libvips': 'true'
73+
},
74+
'sources': [
75+
'src/common.cc',
76+
'src/metadata.cc',
77+
'src/stats.cc',
78+
'src/operations.cc',
79+
'src/pipeline.cc',
80+
'src/utilities.cc',
81+
'src/sharp.cc'
82+
],
83+
'include_dirs': [
84+
'<!@(node -p "require(\'node-addon-api\').include")',
85+
],
86+
'conditions': [
87+
['use_global_libvips == "true"', {
88+
# Use pkg-config for include and lib
89+
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
90+
'conditions': [
91+
['runtime_link == "static"', {
92+
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs --static vips-cpp)']
93+
}, {
94+
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)']
95+
}],
96+
['OS == "linux"', {
97+
'defines': [
98+
# Inspect libvips-cpp.so to determine which C++11 ABI version was used and set _GLIBCXX_USE_CXX11_ABI accordingly. This is quite horrible.
99+
'_GLIBCXX_USE_CXX11_ABI=<!(if readelf -Ws "$(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --variable libdir vips-cpp)/libvips-cpp.so" | c++filt | grep -qF __cxx11;then echo "1";else echo "0";fi)'
100+
]
101+
}]
102+
]
103+
}, {
104+
# Use pre-built libvips stored locally within node_modules
105+
'include_dirs': [
106+
'vendor/include',
107+
'vendor/include/glib-2.0',
108+
'vendor/lib/glib-2.0/include'
109+
],
110+
'conditions': [
111+
['OS == "win"', {
112+
'defines': [
113+
'_ALLOW_KEYWORD_MACROS',
114+
'_FILE_OFFSET_BITS=64'
115+
],
116+
'libraries': [
117+
'../vendor/lib/libvips.lib',
118+
'../vendor/lib/libglib-2.0.lib',
119+
'../vendor/lib/libgobject-2.0.lib'
120+
]
121+
}],
122+
['OS == "mac"', {
123+
'libraries': [
124+
'../vendor/lib/libvips-cpp.42.dylib',
125+
'../vendor/lib/libvips.42.dylib',
126+
'../vendor/lib/libglib-2.0.0.dylib',
127+
'../vendor/lib/libgobject-2.0.0.dylib',
128+
# Ensure runtime linking is relative to sharp.node
129+
'-Wl,-s -rpath \'@loader_path/../../vendor/lib\''
130+
]
131+
}],
132+
['OS == "linux"', {
133+
'defines': [
134+
'_GLIBCXX_USE_CXX11_ABI=0'
135+
],
136+
'libraries': [
137+
'../vendor/lib/libvips-cpp.so',
138+
'../vendor/lib/libvips.so',
139+
'../vendor/lib/libglib-2.0.so',
140+
'../vendor/lib/libgobject-2.0.so',
141+
# Dependencies of dependencies, included for openSUSE support
142+
'../vendor/lib/libcairo.so',
143+
'../vendor/lib/libexif.so',
144+
'../vendor/lib/libexpat.so',
145+
'../vendor/lib/libffi.so',
146+
'../vendor/lib/libfontconfig.so',
147+
'../vendor/lib/libfreetype.so',
148+
'../vendor/lib/libfribidi.so',
149+
'../vendor/lib/libgdk_pixbuf-2.0.so',
150+
'../vendor/lib/libgif.so',
151+
'../vendor/lib/libgio-2.0.so',
152+
'../vendor/lib/libgmodule-2.0.so',
153+
'../vendor/lib/libgsf-1.so',
154+
'../vendor/lib/libgthread-2.0.so',
155+
'../vendor/lib/libharfbuzz.so',
156+
'../vendor/lib/libjpeg.so',
157+
'../vendor/lib/liblcms2.so',
158+
'../vendor/lib/liborc-0.4.so',
159+
'../vendor/lib/libpango-1.0.so',
160+
'../vendor/lib/libpangocairo-1.0.so',
161+
'../vendor/lib/libpangoft2-1.0.so',
162+
'../vendor/lib/libpixman-1.so',
163+
'../vendor/lib/libpng.so',
164+
'../vendor/lib/librsvg-2.so',
165+
'../vendor/lib/libtiff.so',
166+
'../vendor/lib/libwebp.so',
167+
'../vendor/lib/libwebpdemux.so',
168+
'../vendor/lib/libwebpmux.so',
169+
'../vendor/lib/libxml2.so',
170+
'../vendor/lib/libz.so',
171+
# Ensure runtime linking is relative to sharp.node
172+
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$${ORIGIN}/../../vendor/lib\''
173+
]
174+
}]
175+
]
176+
}]
177+
],
178+
'cflags_cc': [
179+
'-std=c++0x',
180+
'-fexceptions',
181+
'-Wall',
182+
'-O3'
183+
],
184+
'xcode_settings': {
185+
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
186+
'CLANG_CXX_LIBRARY': 'libc++',
187+
'MACOSX_DEPLOYMENT_TARGET': '10.7',
188+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
189+
'GCC_ENABLE_CPP_RTTI': 'YES',
190+
'OTHER_CPLUSPLUSFLAGS': [
191+
'-fexceptions',
192+
'-Wall',
193+
'-O3'
194+
]
195+
},
196+
'configurations': {
197+
'Release': {
198+
'conditions': [
199+
['OS == "linux"', {
200+
'cflags_cc': [
201+
'-Wno-cast-function-type'
202+
]
203+
}],
204+
['target_arch == "arm"', {
205+
'cflags_cc': [
206+
'-Wno-psabi'
207+
]
208+
}],
209+
['OS == "win"', {
210+
'msvs_settings': {
211+
'VCCLCompilerTool': {
212+
'ExceptionHandling': 1,
213+
'WholeProgramOptimization': 'true'
214+
},
215+
'VCLibrarianTool': {
216+
'AdditionalOptions': [
217+
'/LTCG:INCREMENTAL'
218+
]
219+
},
220+
'VCLinkerTool': {
221+
'ImageHasSafeExceptionHandlers': 'false',
222+
'OptimizeReferences': 2,
223+
'EnableCOMDATFolding': 2,
224+
'LinkIncremental': 1,
225+
'AdditionalOptions': [
226+
'/LTCG:INCREMENTAL'
227+
]
228+
}
229+
},
230+
'msvs_disabled_warnings': [
231+
4275
232+
]
233+
}]
234+
]
235+
}
236+
},
237+
}]
238+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const sharp = require("sharp");
2+
3+
if (process.argv.length <= 2) {
4+
console.log("convert-image [input-file] [output-file]");
5+
return;
6+
}
7+
sharp(process.argv[2]).toFile(process.argv[3]);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{pkgs?import<nixpkgs> {}}:with pkgs;
2+
let
3+
buildNodeModules = callPackage ../../buildNodeModules.nix {};
4+
in rec {
5+
node_modules = buildNodeModules {
6+
directory = ./.;
7+
buildInputs=[python vips glib.dev pkg-config];
8+
patches = {
9+
"NdEJ9S6AMr8Px0zgtFo1TJjMK/ROMU92MkDtYn2BBrDjIx3YfH9TUyGdzPC+I/L619GeYQc690Vbaxc5FPCCWg==" = ''
10+
cp ${./binding.gyp} package/binding.gyp
11+
'';
12+
};
13+
};
14+
app = runCommand "convert-image" {buildInputs=[nodejs];} ''
15+
mkdir -p $out/bin
16+
ln -s ${node_modules} $out/node_modules
17+
cp ${./convert-image.js} $out/convert-image.js
18+
echo '#!node
19+
require("../convert-image");' > $out/bin/convert-image
20+
chmod +x $out/bin/convert-image
21+
'';
22+
shell = mkShell {
23+
buildInputs = [app];
24+
shellHook = ''
25+
ln -sfn ${node_modules} node_modules
26+
'';
27+
};
28+
}
84.2 KB
Loading

0 commit comments

Comments
 (0)