Skip to content

Commit

Permalink
Merge pull request #55 from gradle/am/swift
Browse files Browse the repository at this point in the history
Add `swiftLibrary` and `swiftApplication` software types
  • Loading branch information
adammurdoch authored May 22, 2024
2 parents a06590a + d1022bf commit 6ffa208
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 43 deletions.
14 changes: 9 additions & 5 deletions unified-prototype/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Declarative Gradle - Unified Plugin Prototypes

This directory contains prototypes of plugins for JVM, Android, and KMP projects built using "unified" plugins that all utilize a similar model and are implemented using the Declarative DSL.
This directory contains prototypes of plugins for JVM, Android, KMP and Swift projects built using "unified" plugins that all utilize a similar model and are implemented using the Declarative DSL.

Currently, these different ecosystems still apply distinct plugins, but those plugins all share a common `plugin-common` dependency, which will gradually grow to contain more functionality.

Expand All @@ -18,7 +18,7 @@ To run the application, use:

## JVM

Sample Java projects live in the `testbed-jvm-library` and `testbed-jvm-application` directories.
Sample JVM projects live in the `testbed-jvm-library` and `testbed-jvm-application` directories.

These samples show the definition of a simple Java application and library that are implemented using a mix of Java 11 and Java 17 source code.

Expand All @@ -40,9 +40,9 @@ To run the application, use:
> ./gradlew testbed-kotlin-jvm-application:run
```

## Kotlin KMP
## Kotlin Multiplatform

The sample Kotlin Multiplatform project lives in the `testbed-kotlin-library` and `testbed-kotlin-application` directories.
The sample Kotlin Multiplatform projects live in the `testbed-kotlin-library` and `testbed-kotlin-application` directories.

The `unified-prototype/plugin-kmp` plugin demonstrates creating extensions using the Declarative DSL, and loading the data from those extensions into the KMP project used by KGP.

Expand Down Expand Up @@ -129,4 +129,8 @@ gradlew :testbed-android-application:assembleDebug

```shell
gradlew :testbed-android-application:assembleRelease
```
```

## Swift

The sample Swift projects live in the `testbed-swift-library` and `testbed-swift-application` directories.
4 changes: 4 additions & 0 deletions unified-prototype/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id("org.gradle.experimental.android-ecosystem")
id("org.gradle.experimental.jvm-ecosystem")
id("org.gradle.experimental.kmp-ecosystem")
id("org.gradle.experimental.swift-ecosystem")
}

dependencyResolutionManagement {
Expand All @@ -26,6 +27,7 @@ include("android-util")
include("java-util")
include("kotlin-jvm-util")
include("kotlin-util")
include("swift-util")
include("testbed-android-library")
include("testbed-android-application")
include("testbed-kotlin-library")
Expand All @@ -36,3 +38,5 @@ include("testbed-jvm-library")
include("testbed-jvm-application")
include("testbed-java-application")
include("testbed-java-library")
include("testbed-swift-library")
include("testbed-swift-application")
3 changes: 3 additions & 0 deletions unified-prototype/swift-util/build.gradle.dcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
swiftLibrary {
swiftVersion = 5
}
6 changes: 6 additions & 0 deletions unified-prototype/swift-util/src/main/swift/Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Utils {
public let welcome = "Welcome to the swift-utils library!"

public init() {
}
}
7 changes: 7 additions & 0 deletions unified-prototype/testbed-swift-application/build.gradle.dcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
swiftApplication {
swiftVersion = 5

dependencies {
implementation(project(":swift-util"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation
import SwiftUtil

print("Hello from Swift")
print(Utils().welcome)
7 changes: 7 additions & 0 deletions unified-prototype/testbed-swift-library/build.gradle.dcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
swiftLibrary {
swiftVersion = 5

dependencies {
implementation(project(":swift-util"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SwiftUtil

class Lib {
let utils = Utils()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.gradle.api.experimental.common;

import org.gradle.api.Action;
import org.gradle.api.tasks.Nested;
import org.gradle.declarative.dsl.model.annotations.Configuring;
import org.gradle.declarative.dsl.model.annotations.Restricted;

/**
* Something that has application dependencies.
*/
@Restricted
public interface HasApplicationDependencies {
@Nested
ApplicationDependencies getDependencies();

@Configuring
default void dependencies(Action<? super ApplicationDependencies> action) {
action.execute(getDependencies());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package org.gradle.api.experimental.jvm;
package org.gradle.api.experimental.common;

import org.gradle.api.Action;
import org.gradle.api.experimental.common.LibraryDependencies;
import org.gradle.api.tasks.Nested;
import org.gradle.declarative.dsl.model.annotations.Configuring;
import org.gradle.declarative.dsl.model.annotations.Restricted;

/**
* Represents a library that runs on the JVM.
* Something that has library dependencies.
*/
@Restricted
public interface HasJvmLibrary {
public interface HasLibraryDependencies {
@Nested
LibraryDependencies getDependencies();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.gradle.api.experimental.java;

import org.gradle.api.experimental.jvm.HasJavaTarget;
import org.gradle.api.experimental.jvm.HasJvmLibrary;
import org.gradle.api.experimental.common.HasLibraryDependencies;
import org.gradle.declarative.dsl.model.annotations.Restricted;

/**
* A library implemented using a single version of Java.
*/
@Restricted
public interface JavaLibrary extends HasJavaTarget, HasJvmLibrary {
public interface JavaLibrary extends HasJavaTarget, HasLibraryDependencies {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.gradle.api.Action;
import org.gradle.api.experimental.common.ApplicationDependencies;
import org.gradle.api.experimental.common.HasApplicationDependencies;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Nested;
import org.gradle.declarative.dsl.model.annotations.Configuring;
Expand All @@ -11,15 +12,7 @@
* Represents an application that runs on the JVM.
*/
@Restricted
public interface HasJvmApplication {
public interface HasJvmApplication extends HasApplicationDependencies {
@Restricted
Property<String> getMainClass();

@Nested
ApplicationDependencies getDependencies();

@Configuring
default void dependencies(Action<? super ApplicationDependencies> action) {
action.execute(getDependencies());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.gradle.api.experimental.jvm;

import org.gradle.api.experimental.common.HasLibraryDependencies;
import org.gradle.declarative.dsl.model.annotations.Restricted;

/**
* A library that runs on the JVM and that is implemented using one or more versions of Java.
*/
@Restricted
public interface JvmLibrary extends HasJavaTargets, HasJvmLibrary {
public interface JvmLibrary extends HasJavaTargets, HasLibraryDependencies {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.gradle.api.experimental.kmp;

import org.gradle.api.Action;
import org.gradle.api.experimental.common.ApplicationDependencies;
import org.gradle.api.experimental.common.HasApplicationDependencies;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
Expand All @@ -12,18 +12,10 @@
* The public DSL interface for a declarative KMP application.
*/
@Restricted
public interface KmpApplication {
public interface KmpApplication extends HasApplicationDependencies {
@Input
Property<String> getLanguageVersion();

@Nested
ApplicationDependencies getDependencies();

@Configuring
default void dependencies(Action<? super ApplicationDependencies> action) {
action.execute(getDependencies());
}

@Nested
KmpApplicationTargetContainer getTargets();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.gradle.api.experimental.kmp;

import org.gradle.api.Action;
import org.gradle.api.experimental.common.LibraryDependencies;
import org.gradle.api.experimental.common.HasLibraryDependencies;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Nested;
Expand All @@ -12,18 +12,10 @@
* The public DSL interface for a declarative KMP library.
*/
@Restricted
public interface KmpLibrary {
public interface KmpLibrary extends HasLibraryDependencies {
@Input
Property<String> getLanguageVersion();

@Nested
LibraryDependencies getDependencies();

@Configuring
default void dependencies(Action<? super LibraryDependencies> action) {
action.execute(getDependencies());
}

@Nested
KmpLibraryTargetContainer getTargets();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.gradle.api.experimental.kotlin;

import org.gradle.api.experimental.jvm.HasJavaTarget;
import org.gradle.api.experimental.jvm.HasJvmLibrary;
import org.gradle.api.experimental.common.HasLibraryDependencies;
import org.gradle.declarative.dsl.model.annotations.Restricted;

/**
* A library implemented using Kotlin and that targets a single JVM version.
*/
@Restricted
public interface KotlinJvmLibrary extends HasJavaTarget, HasJvmLibrary {
public interface KotlinJvmLibrary extends HasJavaTarget, HasLibraryDependencies {
}
30 changes: 30 additions & 0 deletions unified-prototype/unified-plugin/plugin-swift/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
`kotlin-dsl`
id("build-logic.publishing")
}

description = "Implements the declarative Swift DSL prototype"

dependencies {
implementation(project(":plugin-common"))
}

gradlePlugin {
plugins {
create("swift-library") {
id = "org.gradle.experimental.swift-library"
implementationClass = "org.gradle.api.experimental.swift.StandaloneSwiftLibraryPlugin"
tags = setOf("declarative-gradle")
}
create("swift-application") {
id = "org.gradle.experimental.swift-application"
implementationClass = "org.gradle.api.experimental.swift.StandaloneSwiftApplicationPlugin"
tags = setOf("declarative-gradle")
}
create("swift-ecosystem") {
id = "org.gradle.experimental.swift-ecosystem"
implementationClass = "org.gradle.api.experimental.swift.SwiftEcosystemPlugin"
tags = setOf("declarative-gradle")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gradle.api.experimental.swift;

import org.gradle.api.provider.Property;
import org.gradle.declarative.dsl.model.annotations.Restricted;

@Restricted
public interface HasSwiftTarget {
@Restricted
Property<Integer> getSwiftVersion();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.gradle.api.experimental.swift;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.experimental.swift.internal.SwiftPluginSupport;
import org.gradle.api.internal.plugins.software.SoftwareType;
import org.gradle.language.swift.SwiftComponent;
import org.gradle.language.swift.plugins.SwiftApplicationPlugin;

public abstract class StandaloneSwiftApplicationPlugin implements Plugin<Project> {
@SoftwareType(name = "swiftApplication", modelPublicType = SwiftApplication.class)
abstract public SwiftApplication getApplication();

@Override
public void apply(Project project) {
SwiftApplication application = getApplication();

project.getPlugins().apply(SwiftApplicationPlugin.class);

linkDslModelToPlugin(project, application);
}

private void linkDslModelToPlugin(Project project, SwiftApplication application) {
SwiftComponent model = project.getExtensions().getByType(SwiftComponent.class);
SwiftPluginSupport.linkSwiftVersion(application, model);

model.getImplementationDependencies().getDependencies().addAllLater(application.getDependencies().getImplementation().getDependencies());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.gradle.api.experimental.swift;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.experimental.swift.internal.SwiftPluginSupport;
import org.gradle.api.internal.plugins.software.SoftwareType;
import org.gradle.language.swift.plugins.SwiftLibraryPlugin;

public abstract class StandaloneSwiftLibraryPlugin implements Plugin<Project> {
@SoftwareType(name = "swiftLibrary", modelPublicType = SwiftLibrary.class)
abstract public SwiftLibrary getLibrary();

@Override
public void apply(Project project) {
SwiftLibrary library = getLibrary();

project.getPlugins().apply(SwiftLibraryPlugin.class);

linkDslModelToPlugin(project, library);
}

private void linkDslModelToPlugin(Project project, SwiftLibrary library) {
org.gradle.language.swift.SwiftLibrary model = project.getExtensions().getByType(org.gradle.language.swift.SwiftLibrary.class);
SwiftPluginSupport.linkSwiftVersion(library, model);

model.getImplementationDependencies().getDependencies().addAllLater(library.getDependencies().getImplementation().getDependencies());
model.getApiDependencies().getDependencies().addAllLater(library.getDependencies().getApi().getDependencies());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gradle.api.experimental.swift;

import org.gradle.api.experimental.common.HasApplicationDependencies;
import org.gradle.declarative.dsl.model.annotations.Restricted;

@Restricted
public interface SwiftApplication extends HasSwiftTarget, HasApplicationDependencies {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gradle.api.experimental.swift;

import org.gradle.api.Plugin;
import org.gradle.api.initialization.Settings;
import org.gradle.api.internal.plugins.software.RegistersSoftwareTypes;

@RegistersSoftwareTypes({
StandaloneSwiftLibraryPlugin.class,
StandaloneSwiftApplicationPlugin.class})
public class SwiftEcosystemPlugin implements Plugin<Settings> {
@Override
public void apply(Settings target) {
}
}
Loading

0 comments on commit 6ffa208

Please sign in to comment.