Zig bindings for SAP NW RFC SDK, based on version 7.50 patch level 18.
I more or less tried to make them more Zig idiomatic. You might also import and use C headers, but they are less pleasant to work with and lack documentation (see /src/root_raw.zig).
-
You might need to install Visual C++ Redistributable.
-
Get SAP NW RFC SDK from https://support.sap.com/en/product/connectors/nwrfcsdk.html.
-
Add following line to
build.zig(assuming .lib is unpacked tosrc/dllrelative tobuild.zig):exe.addObjectFile(b.path("src/dll/sapnwrfc.lib"));
-
Make sure .dll files are in the same folder as .exe you are trying to run. You might use following command to copy all dll files on build:
b.installDirectory(.{ .source_dir = b.path("src/dll"), .install_dir = .prefix, .install_subdir = "bin", .include_extensions = &.{ "dll" }, });
- Add dependency to
build.zig.zon-
Via zig fetch command
zig fetch --save git+https://github.com/ZigRFC/ZigRFC -
Manually - download repo to e.g. "rfc" folder and add following to
build.zig.zonfile:
.dependencies = .{ .rfc = .{ .path = "rfc", }, },
-
- Add dependency to
build.zigconst depe = b.dependency("rfc", .{ .target = target, .optimize = optimize, }); //Add import to given exe/module exe.root_module.addImport("rfc", depe.module("rfc")); //Alternatively, add directly to given imports .imports = &.{ .{ .name = "rfc", .module = depe.module("rfc") }, },
- Import in code
const rfc = @import("rfc");
https://github.com/ZigRFC/examples_client
https://github.com/ZigRFC/examples_server
Assuming all SDK files and ZigRFC library were added correctly, following example
const std = @import("std");
const rfc = @import("rfc");
const W = std.unicode.utf8ToUtf16LeStringLiteral;
pub fn main() !void {
var login_params: [6]rfc.connection.Parameter = undefined;
var error_info: rfc.ErrorInfo = undefined;
login_params[0].name = W("ashost");
login_params[0].value = W("value");
const connection = rfc.connection.RfcOpenConnection(&login_params, 1, &error_info);
if (connection == null) {
try rfc.PrintErrorToLog(&error_info);
}
}should produce
error: Key=RFC_INVALID_PARAMETER; Message=ASHOST needs SYSNR to be specified