Skip to content

Commit 201b1b1

Browse files
authored
Add a test to validate hostfxr C API (#110169)
1 parent d58ffd1 commit 201b1b1

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

src/native/corehost/hostfxr.h

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#ifndef __HOSTFXR_H__
5-
#define __HOSTFXR_H__
4+
#ifndef HAVE_HOSTFXR_H
5+
#define HAVE_HOSTFXR_H
66

77
#include <stddef.h>
88
#include <stdint.h>
99

10+
#ifdef __cplusplus
11+
extern "C"
12+
{
13+
#endif // __cplusplus
14+
1015
#if defined(_WIN32)
1116
#define HOSTFXR_CALLTYPE __cdecl
1217
#ifdef _WCHAR_T_DEFINED
@@ -296,10 +301,6 @@ struct hostfxr_dotnet_environment_sdk_info
296301
const char_t* path;
297302
};
298303

299-
typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
300-
const struct hostfxr_dotnet_environment_info* info,
301-
void* result_context);
302-
303304
struct hostfxr_dotnet_environment_framework_info
304305
{
305306
size_t size;
@@ -322,6 +323,10 @@ struct hostfxr_dotnet_environment_info
322323
const struct hostfxr_dotnet_environment_framework_info* frameworks;
323324
};
324325

326+
typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
327+
const struct hostfxr_dotnet_environment_info* info,
328+
void* result_context);
329+
325330
//
326331
// Returns available SDKs and frameworks.
327332
//
@@ -415,4 +420,8 @@ typedef int32_t(HOSTFXR_CALLTYPE* hostfxr_resolve_frameworks_for_runtime_config_
415420
/*opt*/ hostfxr_resolve_frameworks_result_fn callback,
416421
/*opt*/ void* result_context);
417422

418-
#endif //__HOSTFXR_H__
423+
#ifdef __cplusplus
424+
}
425+
#endif // __cplusplus
426+
427+
#endif // HAVE_HOSTFXR_H
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Licensed to the .NET Foundation under one or more agreements.
22
# The .NET Foundation licenses this file to you under the MIT license.
33

4-
add_library(mockhostfxr_2_2 SHARED mockhostfxr.cpp)
5-
add_library(mockhostfxr_5_0 SHARED mockhostfxr.cpp)
4+
set(MOCKHOSTFXR_SRC mockhostfxr.cpp test_c_api.c)
5+
6+
add_library(mockhostfxr_2_2 SHARED ${MOCKHOSTFXR_SRC})
7+
add_library(mockhostfxr_5_0 SHARED ${MOCKHOSTFXR_SRC})
68

79
target_link_libraries(mockhostfxr_2_2 PRIVATE libhostcommon)
810
target_link_libraries(mockhostfxr_5_0 PRIVATE libhostcommon)
@@ -11,4 +13,4 @@ target_compile_definitions(mockhostfxr_2_2 PRIVATE MOCKHOSTFXR_2_2 EXPORT_SHARED
1113
target_compile_definitions(mockhostfxr_5_0 PRIVATE MOCKHOSTFXR_5_0 EXPORT_SHARED_API)
1214

1315
install_with_stripped_symbols(mockhostfxr_2_2 TARGETS corehost_test)
14-
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)
16+
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)

src/native/corehost/test/mockhostfxr/mockhostfxr.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
14
#include "error_codes.h"
25
#include "hostfxr.h"
36
#include "host_startup_info.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
// hostfxr.h is a public API. When included in .c files, it may fail to compile
5+
// if C++-specific syntax is used within the extern "C" block. Since all usage of
6+
// this API in runtime repo is within C++ code, such breakages are not encountered
7+
// during normal development or testing.
8+
#include "hostfxr.h"

0 commit comments

Comments
 (0)