Skip to content

Plan for unix support #2

Closed
Closed

Description

@david-bouyssie

Do you have planned to add support for unix platforms?

According to this example it seems to be doable:
https://github.com/dotnet/samples/blob/main/core/hosting/HostWithHostFxr/src/NativeHost/nativehost.cpp

However I have noticed a distinction regarding strings which seem to be wide on windows (typedef wchar_t char_t) but not on unix (typedef char char_t).

Would be happy to contribute to this addition but help might be needed.

Activity

  1. OpenByteDev commented on Mar 10, 2021

    @OpenByteDev
    Owner

    I plan to add unix support, but it is not high on my priority list as I dont personally use it.

  2. david-bouyssie commented on Mar 10, 2021

    @david-bouyssie
    Author

    Ok great, let me know if I can help on a PR.

  3. OpenByteDev commented on Mar 10, 2021

    @OpenByteDev
    Owner

    If you want to implement it yourself I would be more than happy to merge a PR.

  4. david-bouyssie commented on Mar 10, 2021

    @david-bouyssie
    Author

    Well, if you give me a hint of what I should change first, I can work on it.
    I have already identified the WideString vs CString difference, but I may have missed other points.

  5. OpenByteDev commented on Mar 10, 2021

    @OpenByteDev
    Owner

    The difference in string types should be the only change required.

  6. OpenByteDev commented on Mar 24, 2021

    @OpenByteDev
    Owner

    I created an initial version that supports os other than windows.
    It builds, but there are some errors on the tests: https://github.com/OpenByteDev/netcorehost/runs/2180322999?check_suite_focus=true

  7. david-bouyssie commented on Mar 25, 2021

    @david-bouyssie
    Author

    Wow awesome, thank you for this effort!

    It seems that you are linking C++ code with rust. So you have to include the C++ standard library.
    Can you please try with "cargo:rustc-link-lib=dylib=stdc++"?

    For reference: https://users.rust-lang.org/t/linking-c-on-rust-undefined-reference-to-operator-delete-void-and-gxx-personality-v0-libstdc-missing/49658

  8. OpenByteDev commented on Mar 25, 2021

    @OpenByteDev
    Owner

    I already tried that yesterday, but the tests are still failing (now with less errors).
    Interestingly they only seem to fail when run together...

  9. self-assigned this
    on Mar 25, 2021
  10. OpenByteDev commented on Apr 11, 2021

    @OpenByteDev
    Owner

    To clarify:

    • Building succeeds without error.
    • When a specific test is run with cargo test --test [testname] (e.g. cargo test --test hello_world) every test succeeds.
    • When all tests are run at once with cargo test linking fails with this error:
    /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/iostream:74: undefined reference to `std::ios_base::Init::Init()'
    

    The full error log is available here: https://github.com/OpenByteDev/netcorehost/runs/2192279154?check_suite_focus=true

  11. david-bouyssie commented on Apr 12, 2021

    @david-bouyssie
    Author

    This is weird, in this context some headers seem to be loaded from a non-existing directory:
    /opt/rh/devtoolset-7/root/usr/

    I can reproduce the issue on Ubuntu 18.04 (WSL)

  12. david-bouyssie commented on Apr 12, 2021

    @david-bouyssie
    Author

    In bindings\nethost.rs I added this:

    #[link(name = "nethost", kind = "static")]
    #[link(name = "stdc++", kind = "dylib")]
    extern "C" {
        /// Get the path to the hostfxr library
    ...
    

    And I removed from build.rs:

    println!("cargo:rustc-link-lib=dylib=stdc++");
    println!("cargo:rustc-link-lib=static=nethost");
    

    This seems to work.

  13. OpenByteDev commented on Apr 12, 2021

    @OpenByteDev
    Owner

    Nice!
    Do you know why this works and my version did not?

  14. david-bouyssie commented on Apr 12, 2021

    @david-bouyssie
    Author

    No, sorry, I'm missing knowledge there. But maybe on the rust gitter you may have a chance to get some clues.
    I'm not even sure if the proposed solution is the way to go.

  15. david-bouyssie commented on Apr 12, 2021

    @david-bouyssie
    Author

    BTW, I found this other interesting project:
    https://github.com/AaronRobinsonMSFT/DNNE

    It's also based on nethost and provides an utility to generate C source files to be linked against nethost (from exported functions with or without UnmanagedCallersOnly).

  16. OpenByteDev commented on Apr 12, 2021

    @OpenByteDev
    Owner

    It seems that the link attribute does not work for windows? (at least in this situation; again linking errors)

  17. david-bouyssie commented on Apr 13, 2021

    @david-bouyssie
    Author

    I have seen your fix in the commit 0afdcdd

    Looks good to me :)

    Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions