How to build Modernizr with bower and brunch - missing main in bower.json - zurb-foundation

I've read this github issue stating:
there isn't a main file to be in the main.
I have modernizr 3.0.0 installed automatically as a dependency of Foundation 5.5.2 and am trying to build my project with Brunch.
When running brunch build I get the following error:
Error: Component JSON file "/path/to/brunch-test/bower_components/modernizr/.bower.json" must havemainproperty. See https://github.com/paulmillr/read-components#README
So following the read-components issue, I am trying to override modernizr's main in my root bower.json but not sure how to go about it as there's no simple compiled modernizr.js present.
I know modernizr is meant to be customized, and indeed the modernizr 3 release news state there is a really cool solution of dynamically creating a custom package that can be installed via bower but I'm unable to find information about this?

Ok, I figured it out.
So my directory tree is something along the lines of (simplified):
/
|-- bower.json
|-- bower_components
|-- modernizr
|-- bin
|-- modernizr
I went into bower_components/modernizr and ran npm install to get the dependencies required to run the bin/modernizr builder.
Then I went to their website to pick out the features I required: https://modernizr.com/download?setclasses
Next, I clicked Build and downloaded the Command Line Config which I placed at the root directory of my project as modernizr-config.json.
Then I ran bin/modernizr -c ../../modernizr-config.json which placed a custom built modernizr.js in /bower_components/modernizr/modernizr.js
Finally, in my root bower.json, I added (following the read components issue:
"overrides": {
"modernizr": {
"main": "modernizr.js"
}
}
and brunch build is running beautifully now.

Related

How do I link and use LLVM libraries from an Objective-C Xcode project?

I'd like to use a few classes from the LLVM project in my own Objective-C app. Specifically, I want to use the classes declared in BitstreamReader.h and BitstreamWriter.h. Unfortunately, I don't have much experience linking C++ libraries, so I don't really know where to begin. I started by installing llvm through Homebrew with brew install llvm#14. Then, in my Xcode project, I tried linking the libraries in /opt/homebrew/opt/llvm#14/lib, and adding /opt/homebrew/opt/llvm#14/include/** to my HEADER_SEARCH_PATHS.
Now I'm completely stuck. I have a bunch of build errors in Xcode like:
"Reference to unresolved using declaration"
"No member named 'ldiv' in the global namespace"
"Use of undeclared identifier 'wcspbrk'"
...
Any help at all would be greatly appreciated. Thanks!
In C++ world there are quite a few ways to incorporate a dependency into your project, I'll outline some of them, but will try to describe in details one which I find the most suitable for your scenario:
1. Installing libraries system/user-wide
This is the most classic approach, when you have the libraries pre-compiler and pre-installed for your specific platform so they are available under default library search-path. It's similar to how system frameworks in iOS are used - you only add linker command to the project, while the frameworks (libraries) exist independently from it (or don't exist, which causes linker error). The problem with this approach, is that you cannot really use the libs for restricted systems, where "default" libraries are unchangeable (iOS, tvOS, iPadOS)
2. Embedding static libraries
Another approach is to precompile all libraries you need into archives for all platforms the libraries are supposed to be used and then just embed one of the library version which is required into your final app binary. This approach is somewhat cumbersome and unportable because it will require you to compile the lib and re-embed it manually each time you need some parts of library changed or new platform supported.
3. Embedding an xcframework
This approach is very similar to the previous one with a few benefits that you can wrap binaries for all platforms under one package and even release it in SPM.
4. Using CMake build system
Many projects (and LLVM is not an exception) in C++ are made with use of so-called CMake tool. It's widely adopted multi-platform build system and one of the benefits you can employ is that you can easily include any other project as part of your own. At the same time CMake is not widespread at all in the world of mobile development, so you may have hard time finding relevant information for these platforms.
5. Using Xcode workspaces
This is the solution I'd like to describe in more details. In a nutshell this approach consists of 6 steps:
Download LLVM project repo;
Generate Xcode project for required LLVM libraries with use of CMake;
Make an Xcode workspace and add the newly generated project to it;
Add your own project to the same workspace;
Add required dependencies from LLVM project to your own;
Adjust project settings to make it compatible with the dependencies.
The benefits of this approach is that it gives the most consistent experience (after generating project, all parts are configurable from Xcode), freedom of managing the source code (the LLVM project files can be altered however you want), and luxury of built-in dependency graph (all libraries required to build a target are given under Xcode settings).
Downloading LLVM project
You can clone the project from here. Be advised that this has to be in the same folder your future workspace will be in, so you better prepare it in advance:
% mkdir MyWorkspace && cd MyWorkspace
% git clone git#github.com:llvm/llvm-project.git
Generating LLVM Xcode Project
First, ensure you have CMake installed (it doesn't come out of the box with macOS). You can use brew or just download the app from the official site. After that create a new folder for the future Xcode project next to llvm-project repo folder and run cmake on the LLVM toolkit project:
% mkdir LLVM && cd LLVM
% cmake -GXCode ../llvm-project/llvm
Creating Xcode workspace
Nothing fancy here, just open Xcode and navigate to File/New/Workspace menu (Ctrl+Cmd+N shortcut). Ensure that your workspace is created in the MyWorkspace folder. You can just do it from Xcode:
Then, add the LLVM project created on the previous step. Open File/Add Files to "MyWorkspace"... menu (Option+Cmd+A) and select the Xcode project file:
If Xcode suggests to auto-create schemes I recommend accepting this suggestion so you don't have to deal with it yourself later on.
Adding your own project
This step mimics the previous one with exception that you add your own project to the workspace. I didn't have an existing project for that, so I just created a new one (in my case macOS command-line app) in the workspace directory. If you do the same, ensure that the project is added to "MyWorkspace" and the folder is correct:
Eventually your workspace "Project Navigator" should look something like this:
And here is how the directory tree looks like in a nutshell:
% tree -L 2
.
|-- LLVM
| |-- $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
| |-- CMakeCache.txt
| |-- CMakeFiles
| |-- CMakeScripts
| |-- CPackConfig.cmake
| |-- CPackSourceConfig.cmake
| |-- Debug
| |-- LLVM.xcodeproj
| |-- MinSizeRel
| |-- RelWithDebInfo
| |-- Release
| |-- benchmarks
| |-- build
| |-- cmake
| |-- cmake_install.cmake
| |-- docs
| |-- examples
| |-- include
| |-- lib
| |-- llvm.spec
| |-- projects
| |-- runtimes
| |-- test
| |-- third-party
| |-- tools
| |-- unittests
| `-- utils
|-- MyProject
| |-- MyProject
| `-- MyProject.xcodeproj
|-- MyWorkspace.xcworkspace
| |-- contents.xcworkspacedata
| |-- xcshareddata
| `-- xcuserdata
`-- llvm-project
|-- CONTRIBUTING.md
|-- LICENSE.TXT
|-- README.md
|-- SECURITY.md
|-- bolt
|-- clang
|-- clang-tools-extra
|-- cmake
|-- compiler-rt
|-- cross-project-tests
|-- flang
|-- libc
|-- libclc
|-- libcxx
|-- libcxxabi
|-- libunwind
|-- lld
|-- lldb
|-- llvm
|-- llvm-libgcc
|-- mlir
|-- openmp
|-- polly
|-- pstl
|-- runtimes
|-- third-party
`-- utils
Adding dependencies to your project
From this point forward you'll only need Xcode to finish the job. First, let's link the libraries you need to the project and start from the Bitstream archive. Open your project's target General tab settings and under Framework and Libraries click the + sign which should take you to the screen with all local dependencies currently available. It's quite a long list of tools from the LLVM project + native Apple libs, so you may want to filter it as needed to find the required position:
Now the tricky part. You might not actually be required to do that, but if the LLVMBitstreamReader target itself relies on symbols of other libraries (and exposes such a dependency with explicit use of the libraries symbols) the project linking will fail, so to be safe go to the LLVMBitstreamReader build settings and check what it depends on under Target Dependencies section:
Now add these dependencies to your project as well. Eventually your Frameworks and Libraries section should look like this:
Adjusting project settings
CMake generated Xcode projects come with peculiarities. In our case the build folders for the LLVM project targets are located under the project directory with the name matching selected configuration (Debug/Release/MinSizeRel/RelWithDebInfo). In order for your own project's targets to find the libraries built with the given configuration you either have to adjust the LLVM project/targets settings, which I don't recommend because it's a lot of manual work, or just add custom library search path to your project. For the latter go the Build Settings of the target where you added the dependencies at the previous step, find Library Search Path item and add $(SRCROOT)/../LLVM/$(CONFIGURATION)/lib as a new item:
Another tricky part is that dependent targets won't make dependencies to build if the dependencies' targets have incompatible build settings. Incompatible is a vague term here, but commonly it means matching the Architectures section. Luckily in our case it merely means making Release configuration to build active architecture only (the Debug shouldn't require any changes at all):
Last, but not least, the headers of the library. After generating the LLVM Xcode project, the headers it offers don't (completely) come with the project and are actually located in the repository folder. You may just copy the headers right into your own project, but I suggest adding the repo directory in the System Headers Search paths to stay consistent with the LLVM Xcode Project settings (you can yourself check where the headers search paths are under the the LLVMBitstreamReader Build Settings). Similarly to lib search path, I suggest use help of settings variables and add this path flexibly:
$(SRCROOT)/../llvm-project/llvm/include
$(SRCROOT)/../LLVM/include
Finale
At this point you should be good to use the LLVMBitstreamReader library and classes defined there. I renamed my main.m to main.mm so clang knows i'm going to use C++ in my code, and here is my sample code:
//
// main.mm
// MyProject
//
// Created by Aleksandr Medvedev on 14.12.2022.
//
#import <Foundation/Foundation.h>
#import <llvm/Bitstream/BitstreamReader.h>
#import <iostream>
int main(int argc, const char * argv[]) {
llvm::BitstreamBlockInfo::BlockInfo info;
info.Name = "Hello, LLVM!";
std::cout << info.Name << std::endl;
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
}
return 0;
}
If everything is done right, it should compile without any errors now.
P.S. I many times focused on specific directory hierarchy for a reason - when an XCode project is generated through CMake it often uses absolute paths, not relative and if you move your project to another directory, you will have to either adjust the paths in the build settings of required targets/projects or repeat the step with generating the LLVM Xcode project again.

How to build cv2 binding

I have followed the opencv doc for creating my own bindings.
I run the file gen2.py which generated some header files:
./
../
pyopencv_generated_enums.h
pyopencv_generated_funcs.h
pyopencv_generated_include.h
pyopencv_generated_modules_content.h
pyopencv_generated_modules.h
pyopencv_generated_types_content.h
pyopencv_generated_types.h
pyopencv_signatures.json
How should I build this?
I tried running cmake CMakeLists.txt directly in /opencv/modules/python but some defines were not found.
and I tried on re-building running cmake CMakeLists.txt in /opencv/ , where I got:
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
I think both approaches were quite wrong, but I haven't found any doc explaining how to build using the generated headers.
I'm using opencv 4.5.5 which I cloned and built.
EDIT
I found this in /source/opencv/modules/python/bindings/CMakeLists.txt:
string(REPLACE ";" "\n" opencv_hdrs_ "${opencv_hdrs}")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs_}")
add_custom_command(
OUTPUT ${cv2_generated_files}
COMMAND "${PYTHON_DEFAULT_EXECUTABLE}" "${PYTHON_SOURCE_DIR}/src2/gen2.py" "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/headers.txt"
DEPENDS "${PYTHON_SOURCE_DIR}/src2/gen2.py"
"${PYTHON_SOURCE_DIR}/src2/hdr_parser.py"
# not a real build dependency (file(WRITE) result): ${CMAKE_CURRENT_BINARY_DIR}/headers.txt
${opencv_hdrs}
COMMENT "Generate files for Python bindings and documentation"
)
I guess I have to add the path to my headers in ${CMAKE_CURRENT_BINARY_DIR}/headers.txt just not sure how to get the value of CMAKE_CURRENT_BINARY_DIR
EDIT 2
As proposed by #berak, I tried CMAKE_EXTRA_MODULES_PATH=my/path
this seems to get me really close to what I need.
It compiles my sources and generates the .so files as libopencv_xxx.so and saves them in my /usr/local/lib
(when running nm on it I see my class and method)
BUT! when I import cv2 in a script I don't achieve to load my module.
I tried print(cv2.__dict__) and greped on it, but it's not there.
Any clue on how to add the compiled modules into my python-opencv installation?
There's not much documentation on how to create a bind (at least I only found this, which is very helpful but doesn't have all the information).
First, your module must use the following tree structure (I did everything with cmake):
.
src
└── modules
└── your_module
├── CMakeLists.txt
├── include
│   └── opencv2
│   └── your_module_bind_lib.hpp
└── src
└── your_module_bind_lib.cpp
An example of my CMakeLists.txt (this of course may change according to your project):
set(the_description "yourModule LIB")
ocv_define_module(your_module opencv_imgproc WRAP python)
include_directories(${OpenCV_INCLUDE_DIRS})
Then I cloned OpenCV with
git clone https://github.com/opencv/opencv.git
Make a build folder
mkdir wherever/build
And run the following command for cmake
cd wherever/build
cmake -DOPENCV_EXTRA_MODULES_PATH=/project_from_previous_tree/src/modules/ -D BUILD_EXAMPLES=OFF -D BUILD_opencv_apps=OFF -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D CMAKE_INSTALL_PREFIX=/usr/local/ your_opencv_location/opencv/
make -j8
make install
In that command the only "special" thing was DOPENCV_EXTRA_MODULES_PATH (thanks to #berak for the idea).
And then? what happens in python level?
Make sure your python installation actually points to the built opencv, or use something like:
import sys
sys.path.append('/usr/local/lib/python3.8/site-packages/cv2/python-3.8')
import cv2
where /usr/local/lib/python3.8/site-packages/cv2/python-3.8' is where the generated .so is located in my PC.
With this you will be able to use things like
cv2.my_cpp_function()
cv2.my_cpp_class.some_method()
...
Where my_cpp stuff was declared and defined in the module project following the doc and can "easily" have OpenCV typed objects as parameters.
Et voila, now you can use your c++ functions in python.
Notice that this solution does not do any modification to the opencv directory cloned from Git.
You're not supposed to run gen2.py manually, cmake will do this for you at some stage, internally.
since you seem to be on some linux, rather follow the build steps here, this will also generate python bindings, the gist of it is:
make a special "build folder" and cd into it (dont try to build in the src folder, you'll never be able to clean anything up)
run cmake <some args> path_to_src_folder (or better even - cmake-gui) , check if python3 shows up in the "To be build" section of the output
run make install

Installing a 3rd party module for Qt 5.5 in OSX

I want to install Qt Xlsx 3rd party module to use with QtCreator on a OSX system. I tried the instructions provided by the official page but I am failing to compile the code.
What I tried,
My Qt project is on directory: /Users/Documents/Qt Projects/Test
So as instructed in the guide, I copy pasted the source code from gitHub to this directory.
Then I navigated to this working directory through Terminal and executed the following code;
qmake
make
make install
But when I run this code (at command qmake, the terminal returns the following error;
-bash: qmake: command not found
Since this method failed, I tried the second method listed on the guide. But I do not understand second point of this given method. The guide says;
Put the source code in any directory you like. For example, 3rdparty:
|-- project.pro
|-- ....
|-- 3rdparty\
| |-- qtxlsx\
| |
And also the 3rd point which reads;
Add following line to your qmake project file:
include(3rdparty/qtxlsx/src/xlsx/qtxlsx.pri)
What is the qmake project file? Is it the Test.pro file in my working directory? How do I install this module? Please explain clearly since I do not have much experience with Qt.
So made it work;
According to the QtXlsx documentation
I just have to add the following lines to my .pro file.
include(3rdparty/qtxlsx/src/xlsx/qtxlsx.pri)
XLSX_NO_LIB
So the directory of your project should look something like this;
<project folder>/3rdparty/qtxlsx

On running .exe, I am getting a NotImplementedError

I have a python code, which connects to IBM DB2.
It works just fine when I run through the python interpreter.
Now, I have created a .exe file out of it using cx_Freeze
So when I run this .exe file, I get the below error:
NotImplementedError: resource_filename() only supported for .egg, not .zip
The above error is for ibm_db package.
In the site-packages folder, I have these two folders for ibm_db-
ibm_db_dlls
ibm_db-2.0.6-py2.7.egg-info
Setup file:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'WIN32GUI'
include_files = ['dbc.ico', 'excel_funcs.py']
packages = ['ibm_db', 'openpyxl', 'Tkinter', 'os', 'packaging', 'ttk', 'functools', 'time', 'datetime', 'six', 'subprocess', 'tkMessageBox', 'logging']
setup(
name="DB_Checker",
version="1.0",
author="PEJK",
options= {'build_exe' : {'include_files' : include_files, 'packages' : packages, 'includes' : ['re']}},
executables = [Executable('DB_Checker.py', base=base)]
)
Can anyone please suggest what could be the issue.
Thank you.
I know this is an old question but I found a very similar issue with python 3.9, cx_freeze 6.11.1 and ibm_db 3.1.3 on Windows 10.
First, I got the FileNotFoundError that I resolved by correcting the path to the IBM clientdrivers. Then I got the NotImplementedError because the ibm_db.py was not functioning from inside the zipped folder (library.zip).
The cause is that the transformation into executable (cx_freeze) breaks the expected directory structure for ibm_db to work and also by putting the ibm_db and ibm_dbi modules inside the zipped folder where the modules do not work properly.
This is how I eventually worked around the issues without modifying the source code of the two libraries
My setup.py looked like this
from cx_Freeze import setup, Executable
import os, sys
# Dependencies are automatically detected, but it might need
# fine tuning.
build_options = {
'packages': ["ibm_db_dlls"],
'includes': ["clidriver", "ibm_db", "ibm_db_dbi"],
'replace_paths' : [("*", "")],
}
base = 'Console'
executables = [
Executable('main.py', base=base)
]
setup(name='script',
version = '0.1',
description = 'Description...',
options = {'build_exe': build_options},
executables = executables)
Then I built the executable
python setup.py build
This is the structure of the lib folder after transforming the script into an executable:
build\exe.win-amd64-3.9\lib
|-- clidriver
|-- ibm_db_dlls
|-- library.zip
| |-- ibm_db.pyc
| |-- ibm_db_dbi.pyc
If I ran the script I would get FileNotFoundError. Thus, I moved the files ibm_db_dbi.pyc and ibm_db.pyc from the library.zip folder to the parent folder. See the file structure below:
build\exe.win-amd64-3.9\lib
|-- clidriver
|-- ibm_db_dlls
|-- ibm_db.pyc
|-- ibm_db_dbi.pyc
|-- library.zip
Now I am able to run the executable without errors.
I would like the solution to be more fine-tuned than this, e.g. handling this in the setup.py file, but did not find a such solution.

Qt, Linux, GCC: -Wl,-rpath=$ORIGIN not working for platform plugin xcb

I am trying to deploy a C++ application compiled with gcc on Linux by putting the required .so files into the executable directory. I added the linker flag -Wl,-rpath=$ORIGIN so that the program may look for the linked libraries in the directory where it's located. This works so far as that all libraries that are directly linked with my executable are found (checked via ldd).
However, when I try to launch the application I get the following error:
This application failed to start because it could not find or load the Qt platform plugin "xcb".
Available platform plugins are: linuxfb, minimal, offscreen, xcb.
Reinstalling the application may fix this problem.
The platform plugins are located in the folder ./platforms (relative to the executable path). Those some other shared object files which are apparently loaded by Qt, one of them being libqxcb.so. Now, the problem is that this file again depends on libQt5Gui.so, libQt5Core.so etc. These are located in my application path, but I suspect that the libqxcb.so is somehow not able to find them there, thus it fails. Is there a possibility how I could fix this?
If I use the following script to run the application, it works (note: Ct is the name of the executable):
#!/bin/sh
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR
LD_LIBRARY_PATH=LD_LIBRARY_PATH:. ./Ct
But I would like to achieve this without having to use a script to run the application.
The qt deployment document is not particularly helpful with this.
The key to solving this issue is when you look at ldd output of libqxcb.so it goes in the lib folder.
libQt5Core.so.5 => <*>/plugins/platforms/./../../lib/libQt5Core.so.5 (0x00007f5f8374a000)
Therefore the directory structure should be as following:
app
|-- lib
| |-- libQt5Core.so.5
| |-- libQt5Gui.so.5
| |-- libQt5DBus.so.5
| |-- libQt5XcbQpa.so.5
| |-- libicui18n.so.56
| |-- libicuuc.so.56
| `-- libicudata.so.56
|-- qt.conf
|-- app_exec
`-- plugins
`-- platforms
`-- libqxcb.so
In project.pro set your application rpath for lib folder:
unix:!mac{
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN/lib\'"
}
Finally you need to set up qt.conf for your app to be able to find plugins (by default looks from the platforms folder):
[Paths]
Prefix=./
Libraries=lib
Plugins=plugins