在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gradle/native-samples开源软件地址(OpenSource Url):https://github.com/gradle/native-samples开源编程语言(OpenSource Language):Java 42.1%开源软件介绍(OpenSource Introduction):Swift and C++ Sample ProjectsThis repository holds several sample Gradle builds which demonstrate how to use Gradle to build Swift/C++ libraries and applications as introduced in our blog post. Each sample build is listed below with a bit of information related to the features of Gradle that are demonstrated in that build. Each sample is functionally the same for both Swift and C++ languages. Each C++ sample works on macOS, Linux and Windows with GCC, Clang and Visual C++. Each Swift sample works on macOS and Linux, with Swift 3 and later. Deeper build insights with Build ScansYou can generate build-scans with these samples by running Gradle with As an example of adding more data to a build scan, you can also run any sample with Contributing to these samplesIf you want to contribute an improvement to the samples, please refer to the Suggesting new samplesIf you have a use case that isn't covered by an existing sample, open an issue for gradle-native. Please describe what you're trying to accomplish so we can help you find a solution. Visual Studio supportAll of the C++ samples have Visual Studio support, added by applying the
Xcode supportAll of the samples have Xcode support, added by applying the
XCTest supportAll Swift samples demonstrate XCTest support in Gradle. As a user, you can either interact with the test code as you would usually do through Xcode or you can run the test directly from the command line:
Google Test supportThe C++ sample To run the tests from the command line:
Incremental Swift compilationThe Gradle enables Swift incremental compilation by default, so no extra configuration is required to take advantage of this feature with your Swift projects. Debug and release variantsThe Swift and C++ plugins add a 'debug' and 'release' variant for each library or application. By default, the You can also use the At this stage, there are no convenience tasks to build all variants of a library or application. Publishing binaries to a Maven repositorySome of the C++ samples are configured to publish binaries to a local Maven repository. For these samples you can run:
This will build and publish the debug and release binaries. The binaries are published to a repository in the Simple application (application)This sample shows how a simple Swift or C++ application can be built with Gradle. The application has no dependencies and the build has minimal configuration. Although there is currently no out-of-the-box support for building applications and libraries from C, there is also a sample build that shows how the C++ support can be configured to build a C application. C++To build and run the application:
SwiftTo build and run the application:
CTo build and run the application:
Simple Library (simple-library)This sample shows how a Swift or C++ library can be built with Gradle. The library has no dependencies. The build is configured to add unit tests. The C++ sample also adds binary publishing to a Maven repository. C++To build the library:
To run the unit tests for the library:
SwiftTo build the library:
To run the unit tests for the library:
Application with library dependencies in a single build (transitive-dependencies)This sample shows how a C++ or Swift application and several libraries can be built with Gradle and linked together. The sample is structured as a multi-project build, with the application and each library as separate projects in this build. Dependencies are added using project dependencies. In this sample, the application and libraries all use the same implementation language. Mixing C++ and Swift is shown in another sample below. C++To build and run the application:
The build script also demonstrates how to configure convenience tasks like
SwiftTo build and run the application:
Application with Windows Resources (windows-resources)This sample shows how Gradle is able to compile Windows Resources ( C++To build and run the application: (Note the application only runs and build on Windows)
Application with precompiled headers (precompiled-headers)This sample shows how Gradle is able to compile code using precompiled headers.
This sample applies the C++To build and run the application:
Application with library dependencies in a composite build (composite-build)This sample shows how several otherwise independent Swift or C++ libraries can be built together with Gradle. The sample is structured as separate builds for each of the libraries and a composite build that includes these. C++To build and run the application:
SwiftTo build and run the application:
Application with prebuilt library dependencies in a Maven repository (binary-dependencies)This sample shows how to publish C++ libraries to a Maven repository and use them from another build. This is currently not supported for Swift. C++To use the sample, first publish a library to the repository using the
You can find the repository in the Next, build the application that uses the library from this repository.
The build is also configured to download the Google test binaries from a Maven repository to build and run the unit tests:
Application with prebuilt library dependencies (prebuilt-binaries)This sample shows how to use pre-built binaries that are already available on the local machine. Currently, Gradle does not offer a convenient way to do this but it is possible to configure Gradle to use these binaries. C++To use the sample, first create the binaries using the
Next, build and run the application that uses these binaries:
SwiftTo use the sample, first create the binaries using the
Next, build and run the application that uses these binaries:
Application with Swift package manager conventions (swift-package-manager)This sample shows how to configure Gradle to use a source layout that is different to its conventions. In this case, the sample uses the typical layout for a Swift Package Manager package.
It contains an application and a single library. The source files for the application and libraries are all under a single This sample also includes a Swift Package Manager build file, so the same source can be built using Swift Package Manager C++
Swift
Source generation (source-generation)This sample demonstrates using a task to generate source code before building a Swift or C++ application. C++
Generated sources will be under Swift
Generated sources will be under Application with source library dependencies (source-dependencies)This sample demonstrates using external source dependencies to build Swift and C++ applications that require two libraries. The source for the libraries are hosted in separate Git repositories and declared as 'source dependencies' of the application. When Gradle builds the application, it first checks out a revision of the library source and uses this to build the binaries for the library. The Git repositories to use are declared in the build's SwiftTo use this sample, build and run the application:
This will clone version You can see the application's output is incorrect. The build is configured to use version Version
Dynamic dependencies are also supported, so you could also use C++To use this sample, build and run the application:
This will clone version The application output is incorrect because of a bug in the utilities library. Update the application to use a new version that contains a fix:
Application with dependency on upstream branch (dependency-on-upstream-branch)This sample shows how a source dependency on a particular branch can be used. SwiftTo use this sample, create the Git repositories containing the libraries:
Now you can build and run the application:
You can see the application's output is incorrect. The build is configured to use the most recent changes from the 'release' branch of the utilities library and this branch contains a bug. Let's fix this. Edit the source of the utilities library to fix the bug:
There's no need to create a tag, as Gradle will take care of checking out the new branch tip. Now build and run the application:
C++To use this sample, create the Git repositories containing the libraries:
Build and run the application:
Edit the source of the utilities library to fix the bug:
Now build the application:
Application with static library dependencies (static-library)This sample demonstrates building and using static libraries. C++
Swift
Application with operating system specific library dependencies (operating-system-specific-dependencies)This sample demonstrates an application that has dependencies on different libraries for each operating system. Currently, there are no conveniences for using libraries that are installed on the build machine. Swift
The application selects the 'MacOsConsole' library that prints the output in blue when building on macOS. On Linux, it selects the 'LinuxConsole' library that prints the output in green. Each console library is configured to only build on specific operating systems. C++
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论