-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 errors when linting projects that expose C++ in headers #5152
Comments
Can you please share a podspec & its source files so we can reproduce the issue? Thanks! |
The issue here is that we generate an app target in 1.0 which imports a Pod to catch more errors during the linting process. The generated code is ObjC, though, which Pods like yours with C++ headers break, as you already discovered. I see two possible fixes:
I think we can go with the first approach as headers probably won't hit any of the C vs. C++ incompatibilities and the second approach would likely be brittle. |
First one sounds reasonable. Another possibility is generating as .m, compiling, and if that fails, re-generate as .mm, compile again, and if that works it's known to be C++. It would be slower linting for projects that use C++ in the headers, but would avoid any linkage issues for libraries that don't extern "C". |
@kastiglione running |
@segiddins The podspec has since been updated. It was version 0.1 that was failing. |
Hm so since those all still use |
Unfortunately, there's also no real standard for C++ header extensions, it goes all the way from |
Maybe we could switch to generating ObjC++ if |
That's not a bad place to start. |
@neonichu but then that kinda screws of pods like Realm that use c++ but purposefully don't expose any to the user? idk, it just kinda sucks either way :P |
Couldn't just the linter generate a dummy |
But that could (potentially) break imports of raw C headers |
@neonichu
open the temporary lint project like
Rename "main.m" to "main.mm" in xcode.
Run the command which is executed in 'pod lib lint'
Finally, BUILD SUCCEEDED
So could you add a new parameter like '--use-c++' ? The new parameter will create a new temporary lint project. There is a "Main.mm" in this project. This is my podspec: Pod::Spec.new do |s|
s.name = "YTXChart"
s.version = "0.15.1"
s.summary = "YTXChart for pod"
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = "银天下Chart, 依赖AFNetworking"
s.homepage = "http://gitlab.baidao.com/ios/YTXChart.git"
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
s.license = 'MIT'
s.author = { "caojun-mac" => "78612846@qq.com" }
s.source = { :git => "http://gitlab.baidao.com/ios/YTXChart.git", :tag => s.version }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.platform = :ios, '7.0'
s.requires_arc = true
s.source_files = "Pod/Classes/painter/*.{h,m,mm}", "Pod/Classes/painterview/*.{h,m,mm}", "Pod/Classes/chart/*.{h,m,mm}", "Pod/Classes/core/*.{h,mm}", "Pod/Classes/core/**/*.{h,m,mm,inl}"
# s.resource_bundles = {
# 'YTXChart' => ['Pod/Assets/*.png']
# }
s.frameworks = 'Foundation', 'UIKit'
s.libraries = 'sqlite3', 'c++'
s.dependency 'YTXServerId'
s.dependency 'AFNetworking', '~> 2.0'
end PS: This repo lint succeeded at 0.39.0 and build succeeded in xcode GUI by using 'cmd+B'. |
Hi @mdsb100 I have followed your steps and I come at the BUILD SUCCEEDED, But I don't understood when I use the '--use-c++' parameters and finish my repo lint. Can you explain a little more about this steps. Big Thanks. |
@ezefranca '.mm' would include static c++ library like 'std'. 'main.mm' is the entrance, so it must be a '.mm'. We can add a static c++ library in XCode, but it does not work. Unless you rename the main.m to main.mm. '@import' check this import-vs-import-ios-7 I do not know why the c++ project can not be a Module. May be this: You don't actually need to use the @import keyword. If you opt-in to using modules, all #import and #include directives are mapped to use @import automatically. That means that you don't have to change your source code (or the source code of libraries that you download from elsewhere). Supposedly using modules improves the build performance too, especially if you haven't been using PCHs well or if your project has many small source files. You can test simple c++ project and use '@import'. |
@segiddins |
@mdsb100 we haven't really come up with a good fix yet, so that's a prerequisite to implementing one, sorry |
@segiddins |
We don't want to add new command line options for linting unless strictly necessary |
+1 Is there any workaround to this? At least a way to push to a private repo without passing the linting stage? |
@mikewoodworth |
I'd advocate for a |
@mdsb100 niubility! |
1.1.1么 我表示还是不行啊 |
@mdsb100 是1.1.1,我这没问题 |
那你lint能过么?你们不lint的? |
我不lint啊,push成功了不就行了么,push失败了也能看到错误在哪,一般不lint |
Finally, I figure out solution. If you repo call the name is 'YTXChart', And you should add a 'YTXChart.h'. This header file does not contain any c++ header . In a word, 'YTXChart.h' can be empty. You can create a 'YTXChartHeader.h' contains origin content, this header can contain c++. Lint passed! Test in cocoapods@1.1.1 Change your code in your main project:
to
最终,我找到了一个解决方案。 Lint 通过! 测试版本 cocoapods@1.1.1 在你的主工程里面把代码改成:
to
|
@mdsb100 |
当然要Lint,合规啊。我这边是lint不过push也不过的。 |
My workaround was to edit cocoapods source to use C++ then I could push. (Don't worry this is a private repo) |
@ntnmrndn any chance you can make this repo public/forkable? I think we're ready to go the same way. Perhaps we can all pool our efforts to maintain as a fork until they are ready to move on this? |
@mikewoodworth I edited the file in place on my computer. I created a gist with the one file I changed (validator.rb) https://gist.github.com/ntnmrndn/5f91755c12812390b3ae8dec73c1154e I don't think maintaining a fork is a good idea, since it would be incompatible with the main cocoa pods. We should however try to move forward on this issue. |
To sum up the previous talks and current status, it seems
So far the only option I see is to add a field to the podspec. This could looks like this:
If s.public_cpp_header_files contains files, we include them (and just them) in a separate This should preserve backward compatibility and fix our issue. If I could get feedback on this option quickly, I might find the time to implement it. |
@ntnmrndn I think that sounds fair. I think a few other maintainers should weigh in and then perhaps implement this. |
That would be nice |
In 1.2.1.beta.1 a new option Until a much better solution is added I believe the flag should help most to publish. See #6420 |
Is there no "setting" to say that headers in a specific folder are C++ headers? Wouldn't that be a good solution? (I know nothing about implementing it) EDIT: |
使用了 --use-libraries 之后就可以了 |
Summary: Podspec to push yoga 1.8.0 to cocoapods. There is an issue with cocoapods and it fails to lint those projects with C++ in its header, which is the case with yoga too. Follow this thread CocoaPods/CocoaPods#5152. To make the lint pass, one would have to change `app_target_helper.rb` cocoapod source file in the local machine. Follow my [gist](https://gist.github.com/priteshrnandgaonkar/dcca9639a3bc0a3b9adecae3a2b3b0c4). I am able to pass the lint, but not able to push the pod in cocoapods as I am not the admin. @[759512522:emilsj], please push it on Cocoapods or give me permission. Podspec now also exposes public header explicitly. Reviewed By: gkassabli Differential Revision: D7375018 fbshipit-source-id: 4e82e1c0b6340c3f8d3b8a96ecadbcb711d4bcd8
…t` from working. - Files in `*_header_files` must also be included in `source_files` - Eigen needs to be included but doesn't use extensions and so can't be included in `source_files`. Unfortunately it still fails because `pod` uses a `.m` file as the final target, so C++ stuff doesn't build. See CocoaPods/CocoaPods#5152 Remove obsolete iOS GLES stuff, but leave GLU for tessellation
…t` from working. - Files in `*_header_files` must also be included in `source_files` - Eigen needs to be included but doesn't use extensions and so can't be included in `source_files`. Unfortunately it still fails because `pod` uses a `.m` file as the final target, so C++ stuff doesn't build. See CocoaPods/CocoaPods#5152 Remove obsolete iOS GLES stuff, but leave GLU for tessellation Former-commit-id: 9c74f1e
I just spent many hours trying to fix this same thing. Why is this not mentioned anywhere on the CocoaPods website ? |
Report
Using latest beta, there's an issue when linting a library that has C++ in its headers. The file
CocoaPods/Lint/App/main.m
is ObjC, and gets compilation errors when the library has C++ in its headers.What did you do?
pod spec lint --private MyLibrary.podspec
What did you expected to happen?
I expected it to lint successfully. It does with the latest release of cocoapods (0.39.0) but not the latest pre-release (1.0.0.beta.6)
What happened instead?
Build errors pointing to
CocoaPods/Lint/App/main.m
. For example:fatal error: 'unordered_map' file not found
or
error: unknown type name 'namespace'
Podfile
No
Podfile
is involved. This was linting a.podspec
.The text was updated successfully, but these errors were encountered: