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

[nethost] Update nethost #25004

Merged
merged 11 commits into from
Jun 2, 2022
Merged

Conversation

lanyizi
Copy link
Contributor

@lanyizi lanyizi commented May 30, 2022

Describe the pull request

If you are still working on the PR, open it as a Draft: https://github.blog/2019-02-14-introducing-draft-pull-requests/

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one portfile where deprecated functions are used.

If you feel able to do so, please consider migrating them to the new functions:
vcpkg_install_cmake -> vcpkg_cmake_install (from port vcpkg-cmake)
vcpkg_build_cmake -> vcpkg_cmake_build (from port vcpkg-cmake)
vcpkg_configure_cmake -> vcpkg_cmake_configure (Please remove the option PREFER_NINJA) (from port vcpkg-cmake)
vcpkg_fixup_cmake_targets -> vcpkg_cmake_config_fixup (from port vcpkg-cmake-config)

In the ports that use the new function, you have to add the corresponding dependencies:

{
  "name": "vcpkg-cmake",
  "host": true
},
{
  "name": "vcpkg-cmake-config",
  "host": true
}

The following files are affected:

  • ports/nethost/portfile.cmake

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@lanyizi lanyizi changed the title Update nethost [nethost] Update nethost May 30, 2022
@FrankXie05 FrankXie05 self-assigned this May 31, 2022
@FrankXie05 FrankXie05 added the category:port-update The issue is with a library, which is requesting update new revision label May 31, 2022
Copy link
Contributor

@FrankXie05 FrankXie05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that these functions are about to be deprecated, please use the new method.
#25004 (review)

ports/nethost/portfile.cmake Outdated Show resolved Hide resolved
ports/nethost/portfile.cmake Outdated Show resolved Hide resolved
ports/nethost/portfile.cmake Outdated Show resolved Hide resolved
ports/nethost/portfile.cmake Outdated Show resolved Hide resolved
ports/nethost/vcpkg.json Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@lanyizi
Copy link
Contributor Author

lanyizi commented May 31, 2022

I have updated the deprecated functions, for example replacing vcpkg_configure_cmake with vcpkg_cmake_configure, however now the build fails, saying "Unknown CMake command: vcpkg_cmake_configure"...
https://dev.azure.com/vcpkg/public/_build/results?buildId=72951&view=logs&j=878666d5-db33-5b27-9e7d-b0c7ee352005&t=3980505e-92f5-53ef-75a8-4f2e70b97516&l=6015

@FrankXie05
Copy link
Contributor

@lanyizi New functions need dependencies, add dependencies in vcpkg.json:

  "dependencies": [
    {
      "name": "vcpkg-cmake",
      "host": true
    },
    {
      "name": "vcpkg-cmake-config",
      "host": true
    }
  ],

ports/nethost/vcpkg.json Outdated Show resolved Hide resolved
ports/nethost/vcpkg.json Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@lanyizi lanyizi requested a review from FrankXie05 May 31, 2022 09:13
Comment on lines 3 to 5
find_package(unofficial-nethost CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::nethost::nethost) # DLL
target_link_libraries(main PRIVATE unofficial::nethost::libnethost) # Static
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    find_package(unofficial-nethost CONFIG REQUIRED)
    target_link_libraries(main PRIVATE unofficial::nethost::nethost) # DLL
    target_link_libraries(main PRIVATE unofficial::nethost::libnethost) # Static

Is it necessary to separate the linking of dynamic and static libraries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this usage is not available.

CMake Error at /Users/vcpkg/Frank/vcpkg/scripts/buildsystems/vcpkg.cmake:573 (_add_executable):
  Target "test" links to target "unofficial::nethost::nethost" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  CMakeLists.txt:5 (add_executable)

Example CMakeLists.txt:

  1 cmake_minimum_required(VERSION 3.8)
  2
  3 project(test)
  4
  5 add_executable(test "test.cpp")
  6
  7 find_package(unofficial-nethost CONFIG REQUIRED)
  8 target_link_libraries(test PRIVATE unofficial::nethost::nethost) # DLL
  9 target_link_libraries(test PRIVATE unofficial::nethost::libnethost) # Static

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unofficial::nethost::nethost was meant to be used for non-static triplet
So if the current triplet is something like x86-windows-static, then only unofficial::nethost::libnethost is available.

This is also because upstream decided to name the two targets differently, they build the same source twice (both as static and shared library) at the same time:
https://github.com/dotnet/runtime/blob/70ae3df4a6f3c92fb6b315afc405edd10ff38579/src/native/corehost/nethost/CMakeLists.txt#L22
https://github.com/dotnet/runtime/blob/70ae3df4a6f3c92fb6b315afc405edd10ff38579/src/native/corehost/nethost/CMakeLists.txt#L23

If this appears too weird I can edit the patch file so both target have same name. Should I do that?

@FrankXie05
Copy link
Contributor

I found that for upstream they don't want nethost to export both dynamic and static libraries. https://github.com/dotnet/runtime/blob/55e2378d86841ec766ee21d5e504d7724c39b53b/src/native/corehost/nethost/nethost.h#L13.
There is nothing wrong with using the macro NETHOST_USE_AS_STATIC to differentiate, but can we add an option
like -DBUILD_SHARED or -DBUILD_STATIC to differentiate the usage of the exported library?(Maybe this way of yours is better, I'm not sure. I am testing your usage) 🤔

@FrankXie05 FrankXie05 linked an issue May 31, 2022 that may be closed by this pull request
@dg0yt
Copy link
Contributor

dg0yt commented May 31, 2022

can we add an option
like -DBUILD_SHARED or -DBUILD_STATIC to differentiate the usage of the exported library?

Don't invent a new option. Just leverage BUILD_SHARED_LIBS.
https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

@lanyizi
Copy link
Contributor Author

lanyizi commented May 31, 2022

Don't invent a new option. Just leverage BUILD_SHARED_LIBS. https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

I feel BUILD_SHARED_LIBS won't have any effect when building the nethost, because upstream explicitly defined shared / dynamic targets which are being built at the same time...
https://github.com/dotnet/runtime/blob/v6.0.5/src/native/corehost/lib.cmake
https://github.com/dotnet/runtime/blob/v6.0.5/src/native/corehost/lib_static.cmake

@dg0yt
Copy link
Contributor

dg0yt commented May 31, 2022

I feel BUILD_SHARED_LIBS won't have any effect when building the nethost, because upstream explicitly defined shared / dynamic targets which are being built at the same time...

Yes, this CMake anti-pattern is known from other ports. But vcpkg wants only one variant per triplet.

  • You can add patches which use BUILD_SHARED_LIBS for if/else in the CMake build system.
    BUILD_SHARED_LIBS is already passed by vcpkg as needed by the triplet.
  • You can give a usage example which makes use of generator expressions to select the library name.
    Example: Port zstd,
    The package zstd provides CMake targets:
    find_package(zstd CONFIG REQUIRED)
    target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)

@lanyizi
Copy link
Contributor Author

lanyizi commented May 31, 2022

  • You can give a usage example which makes use of generator expressions to select the library name.
    Example: Port zstd,
    The package zstd provides CMake targets:
    find_package(zstd CONFIG REQUIRED)
    target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)

I feel this is easier to do for me (

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@JackBoosY
Copy link
Contributor

Never mind the requests, did you test the usage locally?

@lanyizi
Copy link
Contributor Author

lanyizi commented Jun 1, 2022

Yes, I tested it with both x86-windows and x86-windows-static triplet
If needed I think I could also test x64-windows, but personally I can't test on other platforms (arm or linux)

@JackBoosY JackBoosY added info:reviewed Pull Request changes follow basic guidelines and removed requires:author-response labels Jun 1, 2022
Copy link
Contributor

@ras0219-msft ras0219-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I have reworked the patch to do a few additional things:

  1. Always install the name "unofficial::nethost::nethost", to avoid users needing to write an awful generator expression. If a static build is requested, it's just a link to the libnethost target
  2. Embed the library linkage choice into the header
  3. I searched the source and found no uses of CLI_CMAKE_PLATFORM_ARCH, but I did see CLR_CMAKE_TARGET_ARCH, so I renamed that value.

Please run the following to merge those commits into this PR:

git fetch https://github.com/ras0219-msft/vcpkg dev/roschuma/nethost
git merge FETCH_HEAD

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@lanyizi
Copy link
Contributor Author

lanyizi commented Jun 1, 2022

Thanks for the rework! I have merged the new commit into PR

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

@lanyizi
Copy link
Contributor Author

lanyizi commented Jun 1, 2022

@ras0219-msft Hi! I noticed there was some build errors, for example now the static build didn't include(../lib.cmake) anymore, however lib.cmake introduced some source files which are needed by the static build.
I edited the patch file so those source files are added to static target too.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have modified or added at least one vcpkg.json where you should check the license field.

If you feel able to do so, please consider adding a "license" field to the following files:

  • ports/nethost/vcpkg.json

Valid values for the license field can be found in the documentation

Copy link
Contributor

@ras0219-msft ras0219-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ras0219-msft ras0219-msft merged commit 2aed520 into microsoft:master Jun 2, 2022
@lanyizi lanyizi deleted the update-nethost branch June 18, 2022 15:49
lanyizi added a commit to RA3CoronaDevelopers/WinNetHost that referenced this pull request Oct 5, 2022
vcpkg 那边的依赖可能要等下面这个 PR 通过之后才能使用:
microsoft/vcpkg#25004

或者可以暂时把 vcpkg 的 git 分支切换到我的 fork,然后就能直接安装依赖了(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-update The issue is with a library, which is requesting update new revision info:reviewed Pull Request changes follow basic guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[nethost] update to 2020-10-19
5 participants