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

Configuring SwiftCompile for a static swift-library does not work #1090

Open
bric3 opened this issue Sep 27, 2021 · 1 comment
Open

Configuring SwiftCompile for a static swift-library does not work #1090

bric3 opened this issue Sep 27, 2021 · 1 comment

Comments

@bric3
Copy link

bric3 commented Sep 27, 2021

Following the official documentation (7.2) on swift project on tweaking compiler options, I expected that adding withType<SwiftCompile>().configureEach {} would work but it didn't

Expected Behavior

The configure all work as documented / expected.

tasks.withType<SwiftCompile>().configureEach {
  optimized.set(false)
  debuggable.set(false)
}

Current Behavior

I noticed this on the optimized and debuggable flags in particular, turning them off (with false) isn't applied:

$  ./gradlew :lib:assembleRelease --info | grep swiftc
Starting process 'command '/usr/bin/swiftc''. Working directory: /usr/bin Command: /usr/bin/swiftc --version
Successfully started process 'command '/usr/bin/swiftc''
Starting process 'command '/usr/bin/swiftc''. Working directory: /Users/brice.dutheil/opensource/sandbox/to-be-removed/lib/build/obj/main/release Command: /usr/bin/swiftc -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -parse-as-library /Users/brice.dutheil/opensource/sandbox/to-be-removed/lib/src/main/swift/Hello.swift -module-name Lib -emit-module-path /Users/brice.dutheil/opensource/sandbox/to-be-removed/lib/build/modules/main/release/Lib.swiftmodule -incremental -emit-dependencies -emit-object -g -O -swift-version 5 -output-file-map /Users/brice.dutheil/opensource/sandbox/to-be-removed/lib/build/obj/main/release/output-file-map.json
Successfully started process 'command '/usr/bin/swiftc''

Notice the -g (debug symbols) and -O (optimizations) flags.

Context

When switching shell build scripts using a simpler commands like this

swiftc something.swift -emit-library -o libsomething.dylib

to gradle I noticed awkward code behavior due to optimization turned on.

Steps to Reproduce

This can be reproduced using the a simple gradle init (or via the linked project.zip)

gradle init
Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 3

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 6

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 2

Project name (default: to-be-removed): 

> Task :init
Get more help with your project: https://docs.gradle.org/7.2/samples/sample_building_swift_libraries.html

BUILD SUCCESSFUL in 15s
2 actionable tasks: 2 executed

And adding this to lib/build.gradle.kts

+ tasks.withType(SwiftCompile::class.java).configureEach {
+   optimized.set(false)
+   debuggable.set(false)
+ }

Then run

$ ./gradlew :lib:assembleRelease --info | grep swiftc

Eventually use the outputs.upToDateWhen { false } to force the compilation to re-run.

Workaround

At this point the workaround is to define these flags on the specific variant tasks.

  library {
    // ...
+   binaries.configureEach(SwiftSharedLibrary::class.java) {
+     compileTask.get().run {
+       optimized.set(false)
+       debuggable.set(false)
+     }
+   }
  }

Your Environment

Build scan URL: https://scans.gradle.com/s/jlyikcvpo6rto

$ ./gradlew --version

------------------------------------------------------------
Gradle 7.2
------------------------------------------------------------

Build time:   2021-08-17 09:59:03 UTC
Revision:     a773786b58bb28710e3dc96c4d1a7063628952ad

Kotlin:       1.5.21
Groovy:       3.0.8
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          17 (Amazon.com Inc. 17+35-LTS)
OS:           Mac OS X 11.6 x86_64

$ swiftc --version
Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)
Target: x86_64-apple-darwin20.6.0
@bric3
Copy link
Author

bric3 commented Sep 27, 2021

Ah sorry this issue should be moved over https://github.com/gradle/gradle-native/issues

bric3 referenced this issue in bric3/sandbox Sep 27, 2021
The current touchid swift code has an infinite loop
that gets optimized away with the `-O` flag.
Unfortunately configuring `SwiftCompile` doesn't work, instead
the compiler options have to be configured for each linkage
variant.

See https://github.com/gradle/gradle/issues/18439
@ljacomet ljacomet transferred this issue from gradle/gradle Sep 29, 2021
bric3 added a commit to bric3/sandbox that referenced this issue Sep 29, 2021
The current touchid swift code has an infinite loop
that gets optimized away with the `-O` flag.
Unfortunately configuring `SwiftCompile` doesn't work, instead
the compiler options have to be configured for each linkage
variant.

See gradle/gradle-native#1090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant