Using conan in Bazel for linux but not for windows - bazel

I have a system that is built using Bazel and is using OpenCV as a 3rd party package.
When building on Linux I want to use a prebuilt package using conan, and when using Windows I want to use a locally compiled version, and not use conan.
What I have at the moment is in my WORKSPACE file:
load("#//conan:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()
new_local_repository(
name = "windows_opencv",
build_file = "#//third_party:opencv_windows.BUILD",
path = "C:\\opencv\\build",
)
and the conanfile.txt looks like this:
[requires]
OpenCV/3.4.13#company/dev
[generators]
BazelDeps
BazelToolchain
This works well for the Linux part, but because I don't have the OpenCV/3.4.13#company/dev package for Windows, I can't use conan install and not rules are generated, so trying to build on Windows causes this error:
ERROR: error loading package '': Label '//conan:dependencies.bzl' is invalid because 'conan' is not a package; perhaps you meant to put the colon here: '//:conan/dependencies.bzl'?
The way I currently see this is I have 2 options:
Have 2 conanfile.txt, 1 which contains the OpenCV package and another empty only with the generators, to create the necessary conan files so it would pass the load call
Create an empty OpenCV conan package and again just insall it so the load call would pass
Both options seems to me like bad hacks and workarounds, but I'm not familiar enough with Bazel to know if there's a better option.
What I would like to be able to do is only load the conan dependencies rule for Linux and ignore it on Windows.
Currently the selection between Linux & Windows OpenCV is done using alias:
alias(
name = "opencv_binary",
actual = select({
"//mediapipe:windows": "#windows_opencv//:opencv",
"//conditions:default": "#opencv//:opencv",
}),
)
where #opencv//:opencv is the conan pacakge

Related

octave: add gdal support for mapping package

I am trying to run some old matlab code with octave. Unfortunately this code contains a geotiffread function and I think I should change this function with rasterread (package mapping).
However, when I try to install the mapping package I get this warning:
octave:7> pkg install mapping-1.4.0.tar.gz
configure: WARNING: GDAL library not found. Reading of raster files will be disabled.
For information about changes from previous versions of the mapping package, run 'news mapping'.
I tried to run octave (5.2.0 version) within:
a Debian Buster distribution (snap and flatpak package)
a docker container (MacOS 10.15 host, installed from the mtmiller/octave image).
online with the octave-online service, running this code:
pkg load mapping;
[bands, info] = rasterread ('mexutm250.tiff');
With this output:
octave:3> source("my_script.m")
error: gdalread: reading of raster file with GDAL was disabled during installation
error: called from
rasterread at line 56 column 26
my_script at line 2 column 15
No attempt was successful.
EDIT 2: I know that my octave installations are without GDAL support. I would like to use octave with full mapping package, and GDAL support, without recompile it. There is a way to do it (e.g. update a library path within the docker installation to add the libgdal library)?
If there is no way to add GDAL support without recompile octave, there is a guide to do it with minimal effort?
EDIT 3: I already installed the gdal dependencies:
$ sudo aptitude search gdal |grep ^i
[sudo] password for virtuser:
i gdal-bin - Geospatial Data Abstraction Library - programmi di utilità
i A gdal-data - libreria Geospatial Data Abstraction Library - file di dati
i libgdal-dev - libreria Geospatial Data Abstraction Library - file di sviluppo
i libgdal20 - libreria Geospatial Data Abstraction Library
Thank you.
I got octave with GDAL integration when I installed the octave package from the debian repository. I needed octave 5.2, so I switched to Ubuntu 20.04.
as suggested in one of the comments, checking
>> news mapping
(also at https://octave.sourceforge.io/mapping/NEWS.html)
looking at mapping 1.2.1 where rasterread was introduced, it states:
** New features
Reading GIS raster data: A first go is provided using
functions rasterread.m and rasterinfo.m. Both invoke binary
function gdalread() of which an initial version was provided
by Shashank Khare. rasterread.m and rasterinfo.m can read
and return info on any raster data type that the underlying
GDAL library can read. As such, separate functions for e.g.,
GeoTIFF and ArcGrid etc. are not required.
To make use of these functions the GDAL library must be
present on your system => GDAL is a suggested dependency.
You should be able to install the GDAL library in Debian using your preferred installation method.
Unsure whether or not you'll need to uninstall/reinstall the mapping package afterward, but if an unload/reload doesn't get rid of the message, try that and see if mapping is able to see the library.

Bazel internal shell issue using windows

I am trying to migrate a huge project having visual studio and maven projects to bazel. I need to access our in house maven server which is encrypted. To get access I need the load the maven_jar skylark extension since the default impl does not support encryption (get error 401). using the extension leads to a lot of troubles, like:
ERROR: BUILD:4:1: no such package '#org_bouncycastle_bcpkix_jdk15on//jar': Traceback (most recent call last):
File ".../external/bazel_tools/tools/build_defs/repo/maven_rules.bzl", line 280
_maven_artifact_impl(ctx, "jar", _maven_jar_build_file_te...)
File ".../external/bazel_tools/tools/build_defs/repo/maven_rules.bzl", line 248, in _maven_artifact_impl
fail(("%s: Failed to create dirs in e...))
org_bouncycastle_bcpkix_jdk15on: Failed to create dirs in execution root.
The main issue seems to be the shell that needs to be provided to bazel in BAZEL_SH environment variables:
I am working under windows
I am using bazel 0.23.2
bazel seems to run a bash command using "bash" directly and not the one provided by env variable.
I got a ubuntu shell installed in windows. bazel was using everything from ubuntu, especially when using maven (settings.xml was using from ubuntu ~/.m2 and not from windows user)
after uninstalling ubuntu and making sure that bash in a cmd ends up in "command not found" I also removed the BAZEL_SH env var and bazel throws the message above
after setting the BAZEL_SH variable again it fails with the same error message
I am assuming that bazel gets a bash from somewhere or is ignoring the env variable. My questions are:
1. How to setup a correct shell?
2. Is BAZEL_SH needed when using current version?
For me the doc at bazel website about setup is outdated.
Cheers
Please consider using rules_jvm_external to manage your Maven dependencies. It supports both Windows and private repositories using HTTP Basic Authentication.
For me the doc at bazel website about setup is outdated.
The Bazel team is aware of this and will be updating our docs shortly.

How to install waf?

I have cloned and built the waf script using:
./waf-light configure
Then to build my project (provided by Gomspace) I need to add waf and the eclipse.py to my path. So far I haven't found better than this setenv script:
WAFROOT=~/git/waf/
export PYTHONPATH=$WAFROOT/waflib/extras/:$PYTHONPATH
export PATH=~/git/waf/:$PATH
Called with:
source setenv
This is somehow a pretty ugly solution. Is there a more elegant way to install waf?
You don't install waf. The command you found correctly builds waf: /waf-light configure build Then for each project you create, you put the built waf script into that projects root directory. I can't find a reference, but this is the way in which waf:s primary author Thomas Nagy wants the tool to be used. Projects that repackage waf to make the tool installable aren't "officially sanctioned."
There are advantages and disadvantages with non-installation:
Disadvantages:
You have to add the semi-binary 100kb large waf file to your repository.
Because the file contains binary code, people can have legal objections to distributing it.
Advantages:
It doesn't matter if new versions of waf break the old API.
Users don't need to install waf before compiling the project -- having Python on the system is enough.
Fedora (at least Fedora 22) has a yum package for waf, so you could see that it's possible to do a system install of waf, albeit with a hack.
After you run something like python3 ./waf-light configure build, you'll get a file called waf that's actually a Python script with some binary data at the end. If you put it into /usr/bin and run it as non-root, you'll get an error because it fails to create a directory in /usr/bin. If you run it as root, you'll get the new directory and /usr/bin/waf runs normally.
Here's the trick that I learned from examining the find_lib() function in the waf Python script.
Copy the waf to /usr/bin/waf
As root, run /usr/bin/waf. Notice that it creates a directory. You'll see something like /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18
mv that directory to /usr/lib, dropping the . in the directory name, e.g. mv /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18 /usr/lib/waf-2.0.19-b2f63c807a4215294bf6005410c74c18
If you want to use waf with Python3, repeat Steps 2-3 running the Python script /usr/bin/waf under Python3. Under Python3, the directory names will start with .waf3-/waf3- instead instead of .waf-/waf-.
(Optional) Remove the binary data at the end of /usr/bin/waf.
Now, non-root should be able to just use /usr/bin/waf.
That said, here's something to consider, like what another answer said: I believe waf's author intended waf to be embedded in projects so that each project can use its own version of waf without fear that a project will fail to build when there are newer versions of waf. Thus, the one-global-version use case seems to be not officially supported.

How do I install a project built with bazel?

I am working on a project that is transitioning from CMake to Bazel. One critical feature that we are apparently losing in the bargain is the ability to install the project, so that it can be used by other (not necessarily Bazel) projects.
AFAICT, there is currently no built in support for installing a project?!
I need to create a portable (must work on at least Linux and MacOS) way to install the project. Specifically:
I need to be able to specify libraries, headers, executables, and other files (e.g. LICENSE) that need to be installed.
The user needs to be able to specify an absolute prefix where things should be installed.
I really, really should be able to execute the "install" step more than once, giving different prefixes each time, without Bazel getting confused (i.e. it must not try to "remember" what files it already installed, or if it does, must understand when the prefix is different from last time).
Libraries should be installed to the right place (e.g. lib64), or at least it should be possible for the user to specify the correct libdir.
The install step MUST NOT touch the time stamp on any file from a previous install that has not changed. (Ideally, Bazel itself would handle this; using the install command is tricky and has potential portability issues. Note platform requirements, above.)
What is the best way to go about doing this?
Unless you want to do specific package (e.g. deb or rpm), you probably want to create an executable rule that does the install for you.
You can create a rule that would create an executable (e.g. a shell script) that does the install for you (e.g. do checksums to check if there are change to the installed file and does the actual copy of the files if they have changed). You would have to use the extension language to do, that would look similar to what the docker rules does to load an image with the incremental loader
Addition: I forgot to say that the install itself would be run by using the run command: bazel run install if the rule is named install in the top level BUILD file.

Yocto how to add a gstreamer plugin?

I'm trying to build a custom image for an i.MX6 board by using Yocto.
I want to add the plugin 'gstmotioncells' from Gstreamer OpenCV Plugins ( https://github.com/GStreamer/gst-plugins-bad/tree/master/ext/opencv )
to my build.
But I can't figure out how to add this plugin to my yocto build.
I tried some things but these have not worked.
Do I need to add something to my local.conf file or do I need to modify a .bb file?
After following the instructions of jku, I still got an error.
ERROR: esomimx6-sta-image-1.0-r0 do_rootfs: Unable to install packages. Command '/home/toon/yocto/sta/esomimx6/build_esom/tmp/sysroots/x86_64-linux/usr/bin/opkg --volatile-cache -f /home/toon/yocto/sta/esomimx6/build_esom/tmp/work/esomimx6micro-poky-linux-gnueabi/esomimx6-sta-image/1.0-r0/opkg.conf -o /home/toon/yocto/sta/esomimx6/build_esom/tmp/work/esomimx6micro-poky-linux-gnueabi/esomimx6-sta-image/1.0-r0/rootfs --force_postinstall --prefer-arch-to-version install fsl-alsa-plugins packagegroup-core-ssh-openssh libfreetype6 packagegroup-esom-qt5 cpufrequtils glib-networking libcairo2 openssh-sftp-server packagegroup-core-boot packagegroup-core-x11-base glibmm packagegroup-fsl-gstreamer1.0-full packagegroup-esom-tools-testapps alsa-state ruby packagegroup-fsl-gstreamer1.0 packagegroup-fsl-tools-gpu gstreamer1.0-plugins-bad-opencv packagegroup-fsl-tools-testapps packagegroup-core-tools-debug opkg packagegroup-base-extended libfontconfig1' returned 255:
Collected errors:
* opkg_prepare_url_for_install: Couldn't find anything to satisfy 'gstreamer1.0-plugins-bad-opencv'.
Do you know what is going wrong?
As a first step, you need to enable the opencv plugin in the gstreamer1.0-plugins-bad recipe. There's a packageconfig for that already so this should work in local.conf or your distro configuration:
PACKAGECONFIG_append_pn-gstreamer1.0-plugins-bad = " opencv"
(The space in front of the string is required)
This will make the recipe depend on opencv which is not in the oe-core layer. You will have to add meta-oe to your layers if it's not there already.
You'll also want to add the relevant packages to your image: Probably at least gstreamer1.0-plugins-bad-opencv. In production this would probably happen so that an application recipe that requires the opencv plugin would DEPEND on it. For testing you can just add
IMAGE_INSTALL_append = " gstreamer1.0-plugins-bad-opencv"
into your local.conf.

Resources