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

[release/9.0-staging] Fix hostfxr.h to be valid C again. #110060

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/native/corehost/hostfxr.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef __HOSTFXR_H__
#define __HOSTFXR_H__
#ifndef HAVE_HOSTFXR_H
#define HAVE_HOSTFXR_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

#if defined(_WIN32)
#define HOSTFXR_CALLTYPE __cdecl
#ifdef _WCHAR_T_DEFINED
Expand Down Expand Up @@ -296,10 +301,6 @@ struct hostfxr_dotnet_environment_sdk_info
const char_t* path;
};

typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
const struct hostfxr_dotnet_environment_info* info,
void* result_context);

struct hostfxr_dotnet_environment_framework_info
{
size_t size;
Expand All @@ -322,6 +323,10 @@ struct hostfxr_dotnet_environment_info
const struct hostfxr_dotnet_environment_framework_info* frameworks;
};

typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
const struct hostfxr_dotnet_environment_info* info,
void* result_context);

//
// Returns available SDKs and frameworks.
//
Expand Down Expand Up @@ -384,7 +389,7 @@ struct hostfxr_resolve_frameworks_result
};

typedef void (HOSTFXR_CALLTYPE* hostfxr_resolve_frameworks_result_fn)(
const hostfxr_resolve_frameworks_result* result,
const struct hostfxr_resolve_frameworks_result* result,
void* result_context);

//
Expand All @@ -411,8 +416,12 @@ typedef void (HOSTFXR_CALLTYPE* hostfxr_resolve_frameworks_result_fn)(
//
typedef int32_t(HOSTFXR_CALLTYPE* hostfxr_resolve_frameworks_for_runtime_config_fn)(
const char_t* runtime_config_path,
/*opt*/ const hostfxr_initialize_parameters* parameters,
/*opt*/ const struct hostfxr_initialize_parameters* parameters,
/*opt*/ hostfxr_resolve_frameworks_result_fn callback,
/*opt*/ void* result_context);

#endif //__HOSTFXR_H__
#ifdef __cplusplus
}
#endif // __cplusplus

#endif // HAVE_HOSTFXR_H
8 changes: 5 additions & 3 deletions src/native/corehost/test/mockhostfxr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.

add_library(mockhostfxr_2_2 SHARED mockhostfxr.cpp)
add_library(mockhostfxr_5_0 SHARED mockhostfxr.cpp)
set(MOCKHOSTFXR_SRC mockhostfxr.cpp test_c_api.c)

add_library(mockhostfxr_2_2 SHARED ${MOCKHOSTFXR_SRC})
add_library(mockhostfxr_5_0 SHARED ${MOCKHOSTFXR_SRC})

target_link_libraries(mockhostfxr_2_2 PRIVATE libhostcommon)
target_link_libraries(mockhostfxr_5_0 PRIVATE libhostcommon)
Expand All @@ -11,4 +13,4 @@ target_compile_definitions(mockhostfxr_2_2 PRIVATE MOCKHOSTFXR_2_2 EXPORT_SHARED
target_compile_definitions(mockhostfxr_5_0 PRIVATE MOCKHOSTFXR_5_0 EXPORT_SHARED_API)

install_with_stripped_symbols(mockhostfxr_2_2 TARGETS corehost_test)
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)
3 changes: 3 additions & 0 deletions src/native/corehost/test/mockhostfxr/mockhostfxr.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "error_codes.h"
#include "hostfxr.h"
#include "host_startup_info.h"
Expand Down
8 changes: 8 additions & 0 deletions src/native/corehost/test/mockhostfxr/test_c_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// hostfxr.h is a public API. When included in .c files, it may fail to compile
Copy link
Member

Choose a reason for hiding this comment

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

sounded like there might be one or two other headers that could benefit from similar protection?

Copy link
Member

Choose a reason for hiding this comment

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

Absolutely! The three documented headers: https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting

#include <nethost.h>
#include <coreclr_delegates.h>
#include <hostfxr.h>

I'll fix it in main.

// if C++-specific syntax is used within the extern "C" block. Since all usage of
// this API in runtime repo is within C++ code, such breakages are not encountered
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
// during normal development or testing.
#include "hostfxr.h"
Loading