1515
1616class Nest2DConan (ConanFile ):
1717 name = "nest2d"
18+ author = "UltiMaker"
19+ url = "https://github.com/Ultimaker/libnest2d"
1820 description = "2D irregular bin packaging and nesting library written in modern C++"
1921 topics = ("conan" , "cura" , "prusaslicer" , "nesting" , "c++" , "bin packaging" )
2022 settings = "os" , "compiler" , "build_type" , "arch"
2123 build_policy = "missing"
2224 package_type = "library"
2325 implements = ["auto_header_only" ]
2426
27+ python_requires = "npmpackage/[>=1.0.0]"
2528 options = {
2629 "shared" : [True , False ],
2730 "fPIC" : [True , False ],
2831 "header_only" : [True , False ],
2932 "geometries" : ["clipper" , "boost" ],
3033 "optimizer" : ["nlopt" , "optimlib" ],
31- "threading" : ["std" , "tbb" , "omp" , "none" ]
34+ "threading" : ["std" , "tbb" , "omp" , "none" ],
35+ "with_js_bindings" : [True , False ]
3236 }
3337 default_options = {
3438 "shared" : True ,
3539 "fPIC" : True ,
3640 "header_only" : False ,
3741 "geometries" : "clipper" ,
3842 "optimizer" : "nlopt" ,
39- "threading" : "std"
43+ "threading" : "std" ,
44+ "with_js_bindings" : False
4045 }
4146
4247 def set_version (self ):
@@ -67,12 +72,24 @@ def export_sources(self):
6772 copy (self , "*" , path .join (self .recipe_folder , "include" ), path .join (self .export_sources_folder , "include" ))
6873 copy (self , "*" , path .join (self .recipe_folder , "tests" ), path .join (self .export_sources_folder , "tests" ))
6974 copy (self , "*" , path .join (self .recipe_folder , "tools" ), path .join (self .export_sources_folder , "tools" ))
75+ copy (self , "*" , path .join (self .recipe_folder , "libnest2d_js" ),
76+ os .path .join (self .export_sources_folder , "libnest2d_js" ))
7077
7178 def layout (self ):
7279 cmake_layout (self )
80+ self .cpp .build .bin = []
81+ self .cpp .build .bindirs = []
82+ self .cpp .package .bindirs = ["bin" ]
7383 self .cpp .package .libs = ["nest2d" ]
84+ if self .settings .os == "Emscripten" :
85+ self .cpp .build .bin = ["libnest2d_js.js" ]
86+ self .cpp .package .bin = ["libnest2d_js.js" ]
87+ self .cpp .build .bindirs += ["libnest2d_js" ]
88+
89+ self .cpp .package .includedirs = ["include" ]
7490
7591 def requirements (self ):
92+ self .requires ("spdlog/[>=1.14.1]" , transitive_headers = True )
7693 if self .options .geometries == "clipper" :
7794 self .requires ("clipper/6.4.2@ultimaker/stable" , transitive_headers = True )
7895 if self .options .geometries == "boost" or self .options .geometries == "clipper" :
@@ -133,6 +150,7 @@ def generate(self):
133150 tc .variables ["GEOMETRIES" ] = self .options .geometries
134151 tc .variables ["OPTIMIZER" ] = self .options .optimizer
135152 tc .variables ["THREADING" ] = self .options .threading
153+ tc .variables ["WITH_JS_BINDINGS" ] = self .options .get_safe ("with_js_bindings" , False )
136154
137155 tc .generate ()
138156
@@ -142,7 +160,19 @@ def build(self):
142160 cmake .build ()
143161 cmake .install ()
144162
163+ def deploy (self ):
164+ if self .settings .os == "Emscripten" or self .options .get_safe ("with_js_bindings" , False ):
165+ copy (self , "libnest2d_js*" , src = os .path .join (self .package_folder , "bin" ), dst = self .install_folder )
166+ copy (self , "*" , src = os .path .join (self .package_folder , "bin" ), dst = self .install_folder )
167+
145168 def package (self ):
169+
170+ if self .settings .os == "Emscripten" or self .options .get_safe ("with_js_bindings" , False ):
171+ copy (self , pattern = "libnest2d_js*" , src = os .path .join (self .build_folder , "libnest2d_js" ),
172+ dst = os .path .join (self .package_folder , "bin" ))
173+ copy (self , f"*.d.ts" , src = self .build_folder , dst = os .path .join (self .package_folder , "bin" ), keep_path = False )
174+ copy (self , f"*.js" , src = self .build_folder , dst = os .path .join (self .package_folder , "bin" ), keep_path = False )
175+ copy (self , f"*.wasm" , src = self .build_folder , dst = os .path .join (self .package_folder , "bin" ), keep_path = False )
146176 packager = AutoPackager (self )
147177 packager .run ()
148178
@@ -162,3 +192,10 @@ def package_info(self):
162192 self .cpp_info .defines .append (f"LIBNEST2D_THREADING_{ self .options .threading } " )
163193 if self .settings .os in ["Linux" , "FreeBSD" , "Macos" ] and self .options .threading == "std" :
164194 self .cpp_info .system_libs .append ("pthread" )
195+
196+ # npm package json for Emscripten builds
197+ if self .settings .os == "Emscripten" or self .options .get_safe ("with_js_bindings" , False ):
198+ self .python_requires ["npmpackage" ].module .conf_package_json (self )
199+ # Expose the path to the JS/WASM assets for consumers
200+ js_asset_path = os .path .join (self .package_folder , "bin" )
201+ self .conf_info .define ("user.nest2d:js_path" , js_asset_path )
0 commit comments