This is the in-depth documentation about the OPC UA implementation in Rust.
OPC UA for Rust generally requires the most recent stable version of Rust to compile. The recommendation is to install rustup to manage your toolchain and keep it up to date.
Rust supports two compiler backends - gcc or MSVC, the choice of which is up to you. If you choose the MSVC then you must either build OpenSSL for yourself or use a prebuilt binary.
- Install Microsoft Visual Studio. You must install C++ and 64-bit platform support.
- Use rustup to install the
install stable-x86_64-pc-windows-msvc
during setup or by typingrustup toolchain install stable-x86_64-pc-windows-msvc
from the command line. - If you choose to use a prebuilt-binary, download and install OpenSSL 64-bit binaries, e.g. from https://slproweb.com/products/Win32OpenSSL.html.
- Set an environment variable
OPENSSL_DIR
to point to the installation location, e.g.C:\OpenSSL-Win64
Also if you chose not to copy the OpenSSL binaries to your Windows directory, you must ensure that %OPENSSL_DIR%\bin
is on your PATH
.
set PATH=%PATH%;%OPENSSL_DIR%\bin
32-bit builds should also work by using the 32-bit toolchain and OpenSSL but this is unsupported.
MSYS2 is a Unix style build environment for Windows.
- Install MSYS2 64-bit
- Update all the packages
pacman -Syuu
pacman -S gcc mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-pkg-config openssl openssl-devel pkg-config
- Use rustup to install the
stable-x86_64-pc-windows-gnu
toolchain during setup or by typingrustup toolchain install stable-x86_64-pc-windows-gnu
from the command line.
You should use the MSYS2/MingW64 Shell. You may have to tweak your .bashrc to ensure that the bin/
folders for both Rust and
MinGW64 binaries are on your PATH
.
These instructions apply for apt-get
but if you use DNF on a RedHat / Fedora system then substitute the equivalent packages
and syntax using dnf
.
- Install gcc and OpenSSL development libs & headers, e.g.
sudo apt-get gcc libssl-dev
. - Use rustup to install the latest stable rust during setup.
Package names may vary by dist but as you can see there isn't much to setup.
The major external dependency is OpenSSL. If you have trouble building the openssl-*
crates or trouble running them
then refer to that project's documentation.
The openssl
crate has a vendored
feature that can fetch, build and statically link to a copy of OpenSSL without it
being in your environment.
This might be useful for cross-compiling. OPC UA for Rust exposes the feature as vendored-openssl
which is
on the opcua-core
, opcua-server
and opcua-client
crates. i.e. when you specify --features=vendored-openssl
it will
pass vendored
through to the openssl
crate.
Note that Rust OPC UA is just passing through this feature so refer to the openssl documentation for any issues and troubleshooting required to use it.
The OPC UA server crate also provides some other features that you may or may not want to enable:
generated-address-space
- When enabled (default is enabled), theAddressSpace::new()
will create and populate the address space with the default OPC UA node set. When disabled, the address space will only contain a root node, thus saving memory and also some disk footprint.discovery-server-registration
- When enabled (default is disabled), the server will periodically attempt to register itself with a local discovery server. The server will use the on the client crate which requires more memory.http
- When enabled (default disabled), the server can start an HTTP server (seedemo-server
) providing diagnostic and metrics information about how many active connections there are, what they're monitoring as well as the internal health of the server. This is useful for development and debugging. Enabling the http server adds dependencies onactix-web
and requires more memory.
OPC UA for Rust follows the normal Rust conventions. There is a Cargo.toml
per module that you may use to build the module
and all dependencies. e.g.
$ cd opcua/samples/demo-server
$ cargo build
There is also a workspace Cargo.toml
from the root directory. You may also build the entire workspace like so:
$ cd opcua
$ cargo build