-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Global initialization missing when linking tests against executables #5511
Comments
I was unable to reproduce this issue following the instructions above. Looks like there's no test target in the package, so no tests run and the crash does not occur. Are there additional steps I need to follow? Feel free to reopen with additional repro steps and I'll try it again. |
Sorry, just add the missing test target: diff --git a/Package.swift b/Package.swift
index 6907080..9483b82 100644
--- a/Package.swift
+++ b/Package.swift
@@ -47,5 +47,11 @@ let package = Package(
path: "examples/functype_ec",
exclude: ["README.md", "Makefile"],
plugins: [.plugin(name: "CitronParserGenerator")]),
+
+ .testTarget(
+ name: "ExampleTests",
+ // https://github.com/apple/swift-package-manager/issues/6367
+ dependencies: ["expr"]
+ ),
]
) I'll update the branch with this. |
@grynspan does this help? |
@dschaefer2 I have not had time to look at this issue yet (again), but I haven't forgotten about it. :) |
Sorry for the delay. I was able to reproduce the issue. I am looking at the generated assembly and I think I have a rough understanding of what's happening:
Short-term workaround for @dabrahams: rename main.swift to something else if you can so that you don't get the magic "main file" behaviour. You can still use the @dschaefer2 I'm not 100% sure what the best approach is here for a fix. The compiler's not wrong from its point of view, nor is XCTest. Perhaps we need to pass some flag to the compiler on Darwin saying "treat main.swift the same as any other file"? I think such a flag exists, but I don't know what it is offhand. |
Applying this diff allowed the test to pass locally, which I think confirms my hypothesis: diff --git a/examples/expr/main.swift b/examples/expr/expr.swift
similarity index 88%
rename from examples/expr/main.swift
rename to examples/expr/expr.swift
index 3a0908a..461834b 100644
--- a/examples/expr/main.swift
+++ b/examples/expr/expr.swift
@@ -74,6 +74,8 @@ func parse(_ input: String) throws -> ArithmeticExpression {
return try parser.endParsing()
}
+@main struct Main {
+ static func main() {
if CommandLine.argc != 2 {
print("Pass the expression to be parsed as a quoted argument.")
} else {
@@ -85,3 +87,5 @@ if CommandLine.argc != 2 {
print("Error during parsing: \(error)")
}
}
+ }
+} |
@grynspan thanks. IIRC there were other bugs with |
#3316 may be somewhat incomplete IIUC. If you try to run tests on this branch, you'll find it crashes because the global constants lexer and parser are both 0x00000…
The text was updated successfully, but these errors were encountered: