Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings while compiling to WebAssembly #348

Open
allsey87 opened this issue Dec 27, 2021 · 2 comments
Open

Warnings while compiling to WebAssembly #348

allsey87 opened this issue Dec 27, 2021 · 2 comments
Labels

Comments

@allsey87
Copy link

Hi! I am working on compiling ROS2 nodes to WebAssembly using Emscripten so that I can simulate robot control software in the browser. For the most part, this is going smoothly so far but there are a couple warnings that I think should be addressed:

  1. Conditional compilation in rcutils_get_platform_library_name

rcutils/src/shared_library.c:289:16: warning: unused parameter 'buffer_size' [-Wunused-parameter]
rcutils/src/shared_library.c:290:8: warning: unused parameter 'debug' [-Wunused-parameter]

It seems when I compile using Clang/Emscripten, none of the #ifdefs are matching my configuration in rcutils_get_platform_library_name, which is a bit unusual since I was under the impression that Emscripten defines __LINUX__ (uppercase). I will investigate this, however, there is also the possibility of checking whether __EMSCRIPTEN__ has been defined.

  1. Conditional compilation in rcutils_strerror

rcutils/src/strerror.c:32:10: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]

This warning seems very similar to the previous one. It seems again that conditional compilation has gone down the wrong path since the version strerror_r that comes with Emscripten's C standard library returns an int instead of a char*.

For reference, I am using the Emscripten 3.1.0 (Clang 14.0.0) with the following colcon mixin:

{
    "build": {
        "emscripten": {
            "cmake-args": [
                "-DCMAKE_TOOLCHAIN_FILE=/path/to/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake",
                "-DCMAKE_STAGING_PREFIX=/path/to/developer/emsdk/upstream/emscripten/cache/sysroot/usr/",
                "-DBUILD_SHARED_LIBS=OFF",
                "-DBUILD_TESTING=OFF",
                "--no-warn-unused-cli"
            ]
        }
    }
}
@allsey87
Copy link
Author

Note: Emscripten does support dynamic linking (with so or wasm as the recommended extension), however, it is still a bit strange that shared_library.c is getting compiled at all when BUILD_SHARED_LIBS=OFF...

@aprotyas
Copy link
Member

aprotyas commented Dec 27, 2021

Just for reference - since WASM is a separate virtual ISA, it might be helpful to look at what was done for other platforms (like QNX): ros2/ros2#988.

  1. For point 1, as you alluded, another condition can be added to

    #if defined(__linux__) || defined(__QNXNTO__)

  2. For point 2, rcutils_strerror does have a conditional branch that deals with the XSI-compliant strerror_r signature (second signature), but I think conditional compilation went down the wrong path here too.

    rcutils/src/strerror.c

    Lines 37 to 44 in 6709557

    #else
    /* XSI-compliant */
    int error_status = strerror_r(errno, buffer, buffer_length);
    if (error_status != 0) {
    strncpy(buffer, "Failed to get error", buffer_length);
    buffer[buffer_length - 1] = '\0';
    }
    #endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants