Snap container for open62 stack

Hello,

I have been trying to build a snap for an OPCUA server based on open62541 stack with no luck.

My snap.yaml file contains two parts:

This is the open62 stack which is being built just fine, do I really need to have it built here if my server uses this library?

open62541:
    plugin: cmake
    cmake-parameters:
       - -DBUILD_SHARED_LIBS=ON
       - -DCMAKE_INSTALL_PREFIX=/home/osama/install
       - -DCMAKE_BUILD_TYPE=RelWithDebInfo
       - -DUA_NAMESPACE_ZERO=Full
    source-type: git
    source: https://github.com/open62541/open62541.git
    build-packages:
      - build-essential
      - gcc
      - pkg-config  
      - python3
      - cmake-curses-gui
      - libmbedtls-dev
      - libsubunit-dev

This is my server part which is a cmake project that I can compile just fine with open62 installed on my machine, the problem that I am facing is that when using -libopen62541-1 in stage packages running the snap would fail with error: UA_types has different size in shared object consider re-linking using libopen62541-1-dev: The compilation of the server fails with many errors which I didn’t see before.

opcserver:
    plugin: cmake
    source: ./
    #build-packages:
    #  - libopen62541-1
    #  - libopen62541-1-dev    
    #stage-packages:
    #  - libopen62541-1
    #  - libopen62541-1-dev  

And here is my app:

apps:
  opcserver:
    command: home/osama/OPCServer/src/server/parts/opcserver/src/OPCServer
    plugs:
    - network-bind

I am super new to snapcraft so any recommendations for the structure of the YAML file would be great!

If you use the libopen6254-1 package in stage-packages then you need to not install the open62 manually, but instead use libopen6254-1-dev in build-pacakges.

If you don’t want to use the Ubuntu packages then you need to elide them completely and rely on the build you have for open62.

You also have this: - -DCMAKE_INSTALL_PREFIX=/home/osama/install which will install into the snap at that location - you likely meant it or need it to be - -DCMAKE_INSTALL_PREFIX=/usr.

Thank you for your answer. I did remove libopen62541 and changed the path and the snap is being created fine, but with this warning

Priming opcserver
+ snapcraftctl prime
This part is missing libraries that cannot be satisfied with any available stage-packages known to snapcraft:
- lib/x86_64-linux-gnu/libmbedcrypto.so.3
- lib/x86_64-linux-gnu/libmbedx509.so.0
- usr/local/lib/libopen62541.so.1
These dependencies can be satisfied via additional parts or content sharing. Consider validating configured filesets if this dependency was built.

Should I add anything to opcserver part?

In addition to that, when I try to run the snap the server won’t run completely

[2022-03-23 16:51:39.791 (UTC+0100)] warn/server        AccessControl: Unconfigured AccessControl. Users have all permissions.
[2022-03-23 16:51:39.791 (UTC+0100)] info/server        AccessControl: Anonymous login is enabled
[2022-03-23 16:51:39.791 (UTC+0100)] info/server        AccessControl: x509 certificate user authentication is enabled
[2022-03-23 16:51:39.791 (UTC+0100)] warn/server        Username/Password Authentication configured, but no encrypting SecurityPolicy. This can leak credentials on the network.
[2022-03-23 16:51:39.791 (UTC+0100)] warn/userland      AcceptAll Certificate Verification. Any remote certificate will be accepted.
Segmentation fault

Maybe this is related to the missing libraries?

Staging the following packages fixed the first two warnings:

stage-packages:
      - libmbedx509-0
      - libmbedcrypto3

I still have the warning:

This part is missing libraries that cannot be satisfied with any available stage-packages known to snapcraft:
- usr/local/lib/libopen62541.so.1

And later segmentation fault when running the snap