-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
AOT support #1377
Open
notelgnis
wants to merge
21
commits into
TelegramBots:develop
Choose a base branch
from
notelgnis:aot-support-stj
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
AOT support #1377
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # src/Telegram.Bot/Requests/Available methods/Messages/Location/SendLocationRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/Location/SendVenueRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendAnimationRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendAudioRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendChatActionRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendContactRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendDiceRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendDocumentRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendMediaGroupRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendMessageRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendPhotoRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendPollRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendVideoNoteRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendVideoRequest.cs # src/Telegram.Bot/Requests/Available methods/Messages/SendVoiceRequest.cs # src/Telegram.Bot/Requests/Games/SendGameRequest.cs # src/Telegram.Bot/Requests/Stickers/CreateNewStickerSetRequest.cs # src/Telegram.Bot/Requests/Stickers/SendStickerRequest.cs # src/Telegram.Bot/Types/ReplyMarkups/KeyboardButtonRequestChat.cs # src/Telegram.Bot/Types/StickerSet.cs # src/Telegram.Bot/Types/UsersShared.cs # test/Telegram.Bot.Tests.Unit/EnumConverter/UpdateTypeConverterTests.cs # test/Telegram.Bot.Tests.Unit/Serialization/InputStickerSerializationTests.cs
…on legacy runtimes
…ginal version and the upcoming pull request
Another thing I forgot to mention is that AOT warnings only start appearing in .NET 7. However, the target frameworks have been left unchanged for compatibility reasons. Therefore, to check for any new AOT compatibility warnings, it is necessary to temporarily switch the target framework to .NET 7 or higher. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces support for Ahead-Of-Time (AOT) compilation in the library. As the original branch has already had
System.Text.Json
serialisation implemented, the main effort was to make all the API requests and types involved in communication AOT friendly and to remove everything that wasn't AOT friendly. This introduces another source generator in addition toEnumSerializer.Generator
which is standardSystem.Text.Json
source generator.The library API has been preserved, however, if you for any reason want to serialise or deserialise a request manually in your code (say you get a raw input from your web hook) you'll have to use
TelegramBotClientJsonSerializerContext
like this:The
TelegramBotClientJsonSerializerContext
contains all the generated code needed for serialisation and deserialisation. Another thing worth mentioning is thisTelegramBotClientJsonSerializerContext.Instance
static member which should be used instead of default implementation. The standard implementation ofJsonSerializerContext
generator generatesTelegramBotClientJsonSerializerContext.Default
but it lacks some importantJsonSerializerOptions
likeJsonNamingPolicy.SnakeCaseLower
etc. TheInstance
instance has them. You can also change defaultJsonSerializerOptions
inInstance
like this:However, if you just use the library API methods for sending or polling requests you won't need this and there are no changes needed in your code as well.
Changes
There are some major internal changes in the library though. First comes from the necessity of having two source generators and the fact that the one depends on the output of the other. Two of them don't properly work in the same project so the library has been split in two:
Telegram.Bot
andTelegram.Bot.Base
. The last one includes the code generated byEnumSerializer.Generator
and the first the code generated bySystem.Text.Json
source generator. So, there will be most likely two Nuget packages as well.Other modifications include removing
JsonSerializerOptionsProvider
and some convenient attributes likeCustomJsonDerivedTypeAttribute
,CustomJsonPolymorphicAttribute
,PolymorphicJsonConverter
,PolymorphicJsonConverterFactory
as they weren't AOT friendly.Unit Tests Changes
Unit tests had to be changed as well. To test the same serialisation context that is used in actual API calls it was necessary to test serialisation with the actual (not container-like) types.