-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Android] Add callback to host-runtime contract for getting assembly data #112705
[Android] Add callback to host-runtime contract for getting assembly data #112705
Conversation
Tagging subscribers to this area: @mangod9 |
/azp run runtime |
Azure Pipelines successfully started running 1 pipeline(s). |
@grendello I think a bunch of these changes make sense to me, for example, a bunch of the bundling logic. My pushback would be either we are doing something quick and dirty or we are chasing optimizations, not both. For example I would change the android side to conform, where possible, to existing APIs for now and put a bunch of the cost there. |
This change was incorrectly merged with main and a lot of unrelated commits from main are showing up as part of the delta. Could you please rebase against main and force push so that the delta is reviewable? |
I use |
Using UTF-8 strings on the Android side is easy and bears no costs for us, I can make the change without any effort. This is not the only issue with
👍 |
ff6a948
to
b285800
Compare
…em.native library for the singlefilehost
… R2R that acts like linux
… msbuild places instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we have changes in hosting header files (this one and src/native/corehost/host_runtime_contract.h
below), I think we could consider shipping hosting headers as part of the Android CoreCLR runtime pack?
@elinor-fung @jkotas what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have been treating the coreclr.dll hosting interface as an internal detail that is not officially documented and that is not guaranteed to be stable. Are you suggesting that we change that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we ship headers and still consider them not guaranteed to be stable? That's what mono does with certain parts of its hosting API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to what Steve said:
Currently, on dotnet/macios side the build downloads the coreclrhost.h
header file to build the CoreCLR host:
https://github.com/dotnet/macios/blob/30cce24d4c18d149879fe8afa64331491535ea0b/runtime/Makefile#L38
so with every change to the file, the download URL needs to be updated to have consistent behavior. This is difficult to maintain as the version of the file needs to be aligned with the runtime pack version including the actual implementation changes.
As we are now bringing CoreCLR support for more platforms and as we are in the development stage syncing changes between the runtime and embedders/hosts, I was curious if we would want to ship the required header files as part of the runtime pack (like mono does), to avoid manual downloads or potential mismatches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's always the option of sharing a transport package if we don't want to ship it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want the internal coreclr interface as part of the shipped runtime pack. We do include public hosting headers (coreclr_delegates.h, hostfxr.h, nethost.h) in the host pack.
Transport package seems reasonable if we need a better way for other repos to get at internals.
@elinor-fung it seems like we are stripping this PR down to what is described in: #112706 should we rename the PR and link it to that issue, so that it becomes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change LGTM once we get a successful CI run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Follow-ups I plan on for #112706:
|
Thanks everyone for working together and helping to see this through! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these changes may break source-build, as it effectively regresses #35727. cc: @omajid can you take a look?
@grendello What was the motivation behind this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is expanding the coverage of #35727 to cmake configure step. How is it regressing, do you have an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #35727:
The normal way to do that is by exporting environment variables like CFLAGS and CXXFLAGS. Fedora provides a bunch of values that we can use . But this doesn't play very nice with the liberal use of -Werror in corefx. Worse, the flags leak into various configure tests . For example HAVE_IN_PKTINFO would fail due to an unrelated warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkoritzinsky *FLAGS
must be exported before cmake configuration run, otherwise they will be ignored. Where they were previously exported, they were essentially ignored. My motivation, tbh, was to get color in errors and warnings working, but it just seemed to be a mistake to have the exports without any effect. I think it may also be a requirement for packagers in some Linux distributions. For instance, Debian can specify standard system-wide package compilation flags via various dpkg scripts and it's done by pre-setting the *FLAGS
environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it just seemed to be a mistake to have the exports without any effect.
Before this PR extra flags did had effect but only over cmake --build
step, not the config step.
If something is breaking because of this, it is most likely the problem which needs to be fixed in that config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omajid The policies talk about build, but they don't mean cmake build stage. cmake is a build system generator, so it takes the *FLAGS
into account only when generating the make/ninja build files, during cmake configuration phase. Here's dotnet/runtime's build.ninja
:
artifacts/obj/coreclr/android.arm64.Release $ grep -e '\(CXX\|LD\|CC\)FLAGS' build.ninja | wc -l
0
artifacts/obj/coreclr/android.arm64.Release $ grep -e 'FLAGS' build.ninja | wc -l
2833
artifacts/obj/coreclr/android.arm64.Release $ grep -e 'FLAGS' build.ninja | head -1
FLAGS = -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-rtti -O3 -DNDEBUG -std=gnu++11 -fPIE -O2 -Wall -Wno-null-conversion -glldb -fno-omit-frame-pointer -fwrapv -fstack-protector-strong -Werror -Wno-unused-variable -Wno-unused-value -Wno-unused-function -Wno-tautological-compare -Wno-unknown-pragmas -Wimplicit-fallthrough -Wvla -Wno-invalid-offsetof -Wno-unused-but-set-variable -ffp-contract=off -fno-rtti -Wno-unknown-warning-option -ferror-limit=4096 -Wno-unused-private-field -Wno-constant-logical-operand -Wno-pragma-pack -Wno-incompatible-ms-struct -Wno-reserved-identifier -Wno-unsafe-buffer-usage -Wno-single-bit-bitfield-constant-conversion -Wno-cast-function-type-strict -Wno-switch-default -Wno-nontrivial-memaccess -fsigned-char -fvisibility=hidden -ffunction-sections
As you can see, there's no mention of any of the *FLAGS
- all of them were expanded and placed by cmake configuration stage in the build file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omajid if setting some flags at configure time breaks .NET tests, then the problem is in those tests and it should be fixed there. If any component is incompatible with some flags, it can (and should) check for and remove the offending flags/defines. This post gives a potential solution (not tested by me):
function(remove_compiler_flag target flag)
foreach(property IN COMPILE_DEFINITIONS COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS etc)
# Get the target property
# If the specified flag is in that list, remove it and re-set the target property
endforeach()
endfunction()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omajid, somehow it stopped working. The cmake generated makefiles (or ninja files) do not explicitly account for $CFLAGS etc. from environment variable anymore (assuming it was working when the original issue was fixed):
FROM alpine:latest
RUN apk add --no-cache cmake make ninja gcc musl-dev
WORKDIR /app
RUN cat <<'EOF' > CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(HelloWorld C)
add_executable(hello main.c)
EOF
RUN cat <<'EOF' > main.c
#include <stdio.h>
int main() {
#ifdef PRE_CONFIG_FLAG
#error pre config CFLAGS were respected!
#else
#error pre config CFLAGS were ignored!
#endif
#ifdef POST_CONFIG_FLAG
#error post config CFLAGS were respected!
#else
#error post config CFLAGS were ignored!
#endif
return 0;
}
EOF
ENV CFLAGS="-Wall -Wextra -DPRE_CONFIG_FLAG"
RUN cmake -G Ninja -B build_ninja
RUN cmake -G "Unix Makefiles" -B build_make
ENV CFLAGS="-Wall -Wextra -DPOST_CONFIG_FLAG"
RUN ninja -C build_ninja -v || true
RUN make -C build_make VERBOSE=1
with docker build . -t foo 2>&1 | tee
both ninja and make (penultimate and last lines) show us:
#12 0.125 /app/main.c:5:10: error: #error pre config CFLAGS were respected!
#12 0.125 5 | #error pre config CFLAGS were respected!
#12 0.125 | ^~~~~
#12 0.125 /app/main.c:13:10: error: #error post config CFLAGS were ignored!
#12 0.125 13 | #error post config CFLAGS were ignored!
#12 0.125 | ^~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we revert the part of this change that impacts source build? Or are we ok with fixing outside of runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @am11 and @grendello !
@steveisok said:
Or are we ok with fixing outside of runtime?
Based on the comments and feedback, I think we should fix it as a separate PR. We don't know what that exactly looks like, right now.
Add a new callback to
host_runtime_contract
that is called default assembly resolution:Contributes to #112706
This also makes fatal errors that the runtime prints to
stderr
get printed to logcat on Android.This is a set of minimal changes required to make dotnet/android#9572 (the
.NET for Android
CoreCLR host) work with standard .NET for Android applications.