Good morning everyone.
I am guessing that I have done something wrong here, but before I spend a bunch of time trying to figure out what that might be, I thought I would ask. I figure someone else might have done the same thing at some point.
I have set up my environment to build the CZiti framework on my Mac. To that end, I have done the following, which someone else might find useful:
Install the code for CZiti
The most important part here is the --recurse-submodules as this will ensure all of the components in the SDK are actually present in your local repo. Just issue the following command from the directory you want to store your copy of the Ziti SDK source.
git clone --recurse-submodules https://github.com/openziti/ziti-sdk-swift.git
Install the required dependencies
xcpretty - Depending on which Ruby you are using on your Mac you might need to use sudo to install the gem.
(sudo) gem install xcpretty
cmake - If you do not have Homebrew installed on your Mac, it is highly recommended and makes installing dependencies like this much easier. You can find instructions for installing Homebrew here.
brew install cmake
pkg-config - I had not seen a requirement for this but ran into issues with vcpkg without it, so you will want to install it as well.
brew install pkg-config
vcpkg - Finally, you need to follow the directions in ./deps/ziti-tunnel-sdk-c/build-macosx-x86_64, but the basics are to switch to where you would like to store the vcpkg repository, which includes the scripts/components necessary to build the Ziti SDK. Then issue the following command.
git clone https://github.com/microsoft/vcpkg
You need to set an environment variable that points to the vcpkg directory, so that the build script can find the necessary scripts/components. In my case, that looked like this:
export VCPKG_ROOT=$HOME/Projects/ZPN/ziti-sdk-swift/vcpkg
Run the bootstrap command.
cd vcpkg
./bootstrap-vcpkg.sh
Build the SDK
We are ready to build the SDK.
./build_all.sh
or for a Debug version you can use:
CONFIGURATION=Debug ./build_all.sh
My Build Problem
In my case, the build progressed until it failed with the following error:
.../ziti-sdk-swift/deps/ziti-tunnel-sdk-c/lib/ziti-tunnel-cbs/dns_host.c:245:45: error: incompatible function pointer types passing 'ssize_t (ziti_connection, uint8_t *, ssize_t)' (aka 'long (struct ziti_conn *, unsigned char *, long)') to parameter of type 'ziti_data_cb' (aka 'long (*)(struct ziti_conn *, const unsigned char *, long)') [-Wincompatible-function-pointer-types]
ziti_accept(conn, on_conn_complete, on_dns_req);
.../ziti-sdk-swift/deps/ziti-tunnel-sdk-c/build-iphoneos-arm64/_deps/ziti-sdk-c-src/library/../includes/ziti/ziti.h:761:75: note: passing argument to parameter 'data_cb' here
extern int ziti_accept(ziti_connection clt, ziti_conn_cb cb, ziti_data_cb data_cb);
Potential Solution
Looking at this function, the on_dns_req signature is missing the const keyword for the data argument. As this:
- Function is only used in the ziti_accept call,
- The on_dns_req function is only used in this file
- The data pointer is used only once in the function
- The data pointer is cast to a (const char *) prior to use
It seems reasonable to alter the on_dns_req signature to match the ziti_data_cb signature by adding the const to the argument. That does appear to resolve the build issue. For the reasons above, I don't think this change impacts the runtime usage of the function, but others would have a better idea about this.
My Confusion
I am not sure why this isn't an issue for, well everyone. When I went and looked at the definitions in the git repo, it seems that this code hasn't been touched in a couple of years. Maybe the compiler defaults changed to include -Wincompatible-function-pointer-types by default? I am still unclear how this isn't an issue for others.
Any thoughts on this are appreciated. Thanks.
Mike