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

[build] Reimplement NdkUtils #6083

Merged
merged 1 commit into from
Jul 15, 2021
Merged

Conversation

grendello
Copy link
Contributor

@grendello grendello commented Jul 12, 2021

Context: #5996
Context: #5964
Context: #5964 (comment)

The NdkUtils class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static NdkUtils
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, NdkTools.

NdkUtils had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
NdkUtils was first accessed, meaning that any task using it had to do
it.

NdkTools doesn't require such initialization, instead it provides a
factory method called Create which takes path to the NDK as its
parameter and returns an instance of NdkTools child class (or null
if an error occurs) which the can be safely used by the caller. Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
NdkTools base abstract class.

The hierarchy of NdkTools derivatives is structured and named after
the breaking changes in the NDK. For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
NdkTools, NoClang for NDKs older than r16 and WithClang for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the platforms directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR #6073 which will be merged once r23 is
out of beta.

@grendello grendello force-pushed the ndkutils-rework branch 2 times, most recently from e554928 to c145f56 Compare July 13, 2021 16:43
@grendello grendello force-pushed the ndkutils-rework branch 2 times, most recently from 1441c63 to 8386aca Compare July 14, 2021 07:05
@grendello grendello changed the title Ndkutils rework [build] Reimplement NdkUtils Jul 14, 2021
@grendello grendello marked this pull request as ready for review July 14, 2021 07:06
@jonpryor
Copy link
Member

Context: #5996
Context: #5964
Context: #5964 (comment)

@grendello grendello force-pushed the ndkutils-rework branch 2 times, most recently from a778817 to a07e025 Compare July 14, 2021 20:43
Context: dotnet#5996
Context: dotnet#5964
Context: dotnet#5964 (comment)

The `NdkUtils` class used by Xamarin.Andrid.Build.Tasks to find tooling
shipped with the Android NDK, has grown increasingly complicated over
the years due to a number of incompatibilities between various versions
of the NDK. The code became hard to follow and untidy. This commit
attempts to address the issue by replacing the single static `NdkUtils`
class with a hierarchy of dynamically instantiated classes rooted in a
new base class, `NdkTools`.

`NdkUtils` had to be initialized for each thread that needed to access
its methods, which led to various issues with concurrency and lack of
proper initialization since the initialization had to be done wherever
`NdkUtils` was first accessed, meaning that any task using it had to do
it.

`NdkTools` doesn't require such initialization, instead it provides a
factory method called `Create` which takes path to the NDK as its
parameter and returns an instance of `NdkTools` child class (or `null`
if an error occurs) which the can be safely used by the caller.  Callers
need not concern themselves with what is the actual type of the returned
instance, they access only methods and properties defined in the
`NdkTools` base abstract class.

The hierarchy of `NdkTools` derivatives is structured and named after
the breaking changes in the NDK.  For instance, NDK versions before 16
used the GNU compilers, while release 16 and above use the clang
compilers - this is reflected in existence of two classes derived from
`NdkTools`, `NoClang` for NDKs older than r16 and `WithClang` for the
newer ones. The other breaking changes are the addition of unified
headers in r19, removal of the `platforms` directory in r22 and removal
of GNU Binutils in r23.

NDK r23 is recognized in this commit but it is NOT supported. Support
for r23 is being worked on in PR dotnet#6073 which will be merged once r23 is
out of beta.
@jonpryor jonpryor merged commit 71ae556 into dotnet:main Jul 15, 2021
@grendello grendello deleted the ndkutils-rework branch July 15, 2021 13:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants