I am migrating my Cmake project to Bazel. At the root of my project is a build folder that I use to run Cmake.
To migrate to Bazel, I need to create a BUILD file at the root of my project. However, on macOS, I cannot create it due to the presence of my build folder.
Can I use a different name for Bazel's BUILD files? Or should I get rid of my build folder?
Bazel also supports using BUILD.bazel as the filename, which should resolve this issue (BUILD.bazel is preferred if both BUILD.bazel and BUILD exist).
Please try using that and see if it helps!
Related
Our iOS app currently is using Google protobuffer gRPC as our API layer to communicate between App and backend. And so we have these .proto files in our backend directory which will be converting to .grpc.swift and .pb.swift files by gRPC-Swift-Plugins and then consumed by the App.
This works okay, but the process of converting is very tedious, and we would like to automate the whole process.
Below is how we're doing it:
Delete previously copied directory, and copy all .proto files from backend (.proto files are maintained by backend devs) to App directory named "Protos" via a shell script
We already set up Build rules and include .proto files in Compile Sources. Following the steps from an answer here on SO
Screenshot of the current setup in Xcode Build Rules:
Whenever we build the project, .pb.swift and .grpc.swift are generated and putting into a directory named "generated" under the "Protos" folder.
Here are the problems:
If the backend added a new .proto files into the source directory, my script will only copy the files into the Protos directory but not included news files in the Compile Sources list.
Similar to the first problem, we need to manually set up Compile Sources in Xcode and that means if a new dev joins our team, he/she also needs to do the same setup again.
We sometimes need to refer to the .grpc.swift and .ph.swift files while coding. But If we add these files into Xcode and build the project again, Xcode will complain that these generated files are there like (Sorry, we're working on a private repo, so the project name and file names are replaced):
Multiple commands produce '${user_path}/${proto_name}.pb.o':
Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
Target '${my_project_name}' (project '${my_project_name}') has compile command for Swift source files
Any answers or comments and suggestions are greatly appreciated!
It's interesting I didn't have those problems with Swift if I use the $DERIVED_FILE_DIR
protoc "$INPUT_FILE_NAME" --swift_out="$DERIVED_FILE_DIR" --proto_path="Your/proto/path"
I don't use the plugin because I've got the plugin installed in my /usr/local/bin
But I have exactly those problems when we use the output for cpp files.
We have different build configurations in our project, like the release, debug, sandbox, etc. The interesting case is when I archived from the release or debug build configuration, all archive files extracted as expected as shown in Image 1, but If I change build configuration to sandbox, some files and folders are missing as shown in Image 2.
Although we created custom build configurations by duplicating from debug or release, the archive doesn't contain all files or folders like in Image 1.
We use carthage(for internal network) and cocoapods(for others) as a dependency manager.
I tried many suggestions but couldn't find a solution.
Like,
setting skip install to NO in build settings,
removing all archive and derived data files, clean and re-archive,
giving the archive folder to read & write permission
Thank you all
If you're using Carthage for internal frameworks you should have same custom build configurations for them, too. Otherwise, it will bootstrap with Release configuration automatically which won't generate SwiftSupport files etc.
You also can avoid this by adding below before archiving in your custom configurations.
carthage bootstrap --configuration Debug
You should make sure that those files are included in Build Phases -> Copy Bundle Resources
As part of the pub build process, I would like pub to copy a file from $PROJECT_ROOT/third_party/foo/foo.png to $PROJECT_ROOT/build/web/foo.png to make it accessible to my code at runtime. How can I configure pub to copy the file for me using pubspec.yaml?
You can't.
You can use for example Grinder and automate your build tasks with it. It makes it easy to invoke pub build and copying files with a few lines of Dart code.
You can use symlink for that. It will be automatically copied during pub build to your build directory and will always be the same file as in your root directory during debug.
You may symlink the whole folder or single file to your web folder.
pub does exactly the same with packages folder. In linux or macosx its quite easy using ln -s command. In windows, here is good explanation how to do that.
I have an ios project that builds with CMake 3.1.1, but I am stuck on the last problem - getting CMake to copy the asset directory into the right location for the app.
I have this, which works when running the app in the simulator. However, it does not work, and in fact causes a build failure when archiving because the destination directory it constructs does not exist.
get_target_property(APPLICATION_BIN ${APPLICATION_NAME} LOCATION)
get_dotapp_dir(${APPLICATION_BIN} APPLICATION_APP_LOCATION)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND cp -r "${CMAKE_SOURCE_DIR}/assets" "${APPLICATION_APP_LOCATION}")
The directory I am copying has many subdirectories and I need them all preserved. Essentially I want to accomplish with cmake the same thing that happens when I drag the "assets" folder into the ios project underneath "Resources".
Use ${CMAKE_COMMAND} -E copy_directory instead of calling cp.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS "${PROJECT_SOURCE_DIR}/assets" COMMAND -E copy_directory ${PROJECT_SOURCE_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP})
add_custom_target(${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS
My solution to this is similar to this answer. The goal of my project was to get googletests running on a cross-platform library, in which I had to wrap googletests into an XCTest Bundle. The build tool we are converting to is CMake for obvious reasons.
I ended up doing this as a pre-build step:
add_custom_command(TARGET ExampleTestTarget PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/resources $<TARGET_FILE_DIR:ExampleTestTarget>
)
Essentially, at prebuild, CMake will copy everything in the resources folder into the root of the target's bundle. For some reason (probably a CMake thing), XCode picked these resource files up with no issue, so I didn't have to set the files to be RESOURCE files explicitly.
If you're using MacOS Bundles/Packages/etc., you'll have to copy-paste these files into $<TARGET_FILE_DIR:ExampleTestTarget>/Resources instead since this is the default resource location for MacOS xcodeproj's generated by CMake. (There are so many loopholes to get XCTests working in CMake that I advise everyone doing cross-platform gtests to create an executable instead for MacOS so you won't get into any trouble like this anyway).
Note, you won't see the files in XCode unless you add the files in target_sources(), but who cares... it works anyway! Who develops C++ exclusively in iOS? ....
in a XCode project, I offen got xcodeproject/project.pbxproj file changed, but useless info for me, it for compile.
Should I git ignore this file and xcodeproject/projectxworkspace/username.xcuserdata/UserInterfaceState.xcuserstate file?
Update in the light of Swift Package Manager: If you're building a project as a Swift package - you should definitely ignore this file as it can be generated using file system as source of truth. You can do that by using the following command:
$ cd ~/Projects/MyProjectFolder/
$ swift package generate-xcodeproj
For non-SwiftPM answer - see below.
This file holds the list of all the files in the project, settings of targets and which files belong to which targets. It's probably the meatiest file in project bundle. You should not ignore this file. There are few points for this:
You may not want to work on this project alone or;
You're planning on working on project from different machines;
You'll want to share your code base with others;
That is the only file that you want in your repos from the xcodeproj bundle. That file holds all of the info for targets files and build settings.
Unfortunately, if your Build Settings includes code signing, you have to re-enter your code-signing entity after every "git pull" if another team member has changed it. It seems to me this info should be in the user settings, not the global pbxproj file.
project.pbxproj is an important file in the Xcode configuration bundle. It is responsible for maintaining references to all of the linked files and their groupings, linked frameworks, and most importantly, the project’s build settings. Because of this, we cannot exclude project.pbxproj from version control.
Here is my general .gitignore for my Xcode Project.
# OS X Finder
.DS_Store
# Xcode per-user config
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace
xcuserdata
# Build products
build/
*.o
*.LinkFileList
*.hmap
# Automatic backup files
*~.nib/
*.swp
*~
*.dat
*.dep
If you exclude project.pbxproj Jenkins builds will fail. So this is important if you use Jenkins.
You can use Xcodegen to generate a pbxproj out of a YAML project specification file then you can ignore pbxproj in git and generate them every time you need.
I have already used Xcodegen on a second project which has a modular architecture (many pbxprojs) and more then 8 developers is working on it.
https://github.com/yonaskolb/XcodeGen
Hope it helps.
I found that I also need to preserve the xcworkspace file(s). If didn't, project with a sub-project broke.