Build macOS prebuilts for arm64 and x86_64#2601
Conversation
961b231 to
1605667
Compare
ygurov
left a comment
There was a problem hiding this comment.
Left some comments for a single recipe though to be applied for all modified recipes
| return self.settings.get_safe("os.version") | ||
|
|
||
| def _go_env(self, goarch): | ||
| env = Environment() |
There was a problem hiding this comment.
Do not use Environment manually, or not as a main one - it ignores externally-specified flags and Conan internals passing to the Makefile.
Use an env on a top of this one instead
tc = AutotoolsToolchain(self)
env = tc.environment()
| env = Environment() | ||
| env.define("GOOS", self._goos) | ||
| env.define("GOARCH", goarch) | ||
| env.define("GOROOT", self.dependencies.build["go"].package_folder) |
There was a problem hiding this comment.
Do not specify GOROOT - it does not change the actual go executable used, just replaces the toolchain location.
I see we have issues with passing our external go in here, so let's use this one as a first line in def generate(self). Should resolve the issue
VirtualBuildEnv(self).generate()
| env.define("GOARCH", goarch) | ||
| env.define("GOROOT", self.dependencies.build["go"].package_folder) | ||
| env.define("GOPATH", os.path.join(self.build_folder, "gopath")) | ||
| env.define("GOMODCACHE", os.path.join(self.build_folder, "gopath", "pkg", "mod")) |
There was a problem hiding this comment.
Hmm, specifying this one is not a bad idea!
Let's do it for all platforms, should make builds more consistent
| return env | ||
|
|
||
| def _cgo_arch_flags(self, goarch): | ||
| return f"-arch {self._clang_arch_map[goarch]}" |
There was a problem hiding this comment.
-arch option used in here allows values in apple-clang-internal format, not the golang one.
These values are corresponding with the ones used in Conan, so let's just use them
Moreover, Conan does specify multiple -arch flags itself during generate step if AutotoolsToolchain is used.
| env.define("GOCACHE", os.path.join(self.build_folder, "gocache")) | ||
| env.define("GOTELEMETRY", "off") | ||
| if self._macos_deployment_target: | ||
| env.define("MACOSX_DEPLOYMENT_TARGET", self._macos_deployment_target) |
There was a problem hiding this comment.
This one would be specified automatically if AutotoolsToolchain is used. I would suggest just make a proper generate step instead of applying every flag manually
| env.define("GOTELEMETRY", "off") | ||
| if self._macos_deployment_target: | ||
| env.define("MACOSX_DEPLOYMENT_TARGET", self._macos_deployment_target) | ||
| env.prepend_path("PATH", self._go_bin_path) |
There was a problem hiding this comment.
That's a bad idea. Use the one suggested in
https://github.com/amnezia-vpn/amnezia-client/pull/2601/changes#r3247262682
| def _cgo_arch_flags(self, goarch): | ||
| return f"-arch {self._clang_arch_map[goarch]}" | ||
|
|
||
| def _build_go_arch(self, goarch): |
There was a problem hiding this comment.
DRY
Let's use an existing build step iterating all over archs, and use lipo then
There was a problem hiding this comment.
I still have a complaint about the building process - there should be a single function which does the job.
I find trying to put something into the hooks a very bad practice. Recipe becomes unclear to read and analyze in the future
DRY KISS
There was a problem hiding this comment.
This one is still unresolved
| env.define("CGO_CFLAGS", self._cgo_arch_flags(goarch)) | ||
| env.define("CGO_LDFLAGS", self._cgo_arch_flags(goarch)) | ||
| with env.vars(self).apply(): | ||
| self.run("make", env=None) |
There was a problem hiding this comment.
Do not run make manually, use
at = Autotools(self)
at.make()
Otherwise, it would ignore all Conan internal-specified variables
c079e7f to
91cc9f1
Compare
91cc9f1 to
d1c6cd4
Compare
ca4a82a to
966c9c6
Compare
966c9c6 to
6e7925b
Compare
ygurov
left a comment
There was a problem hiding this comment.
Once again, reviewed just a single recipe, but to be applied for every changed one
|
|
||
| if(APPLE AND NOT IOS AND NOT MACOS_NE) | ||
| set(SIGN_OVPN_SCRIPT [=[ | ||
| if [ "$CODE_SIGNING_ALLOWED" != "NO" ]; then |
There was a problem hiding this comment.
This is a huge hack that should be avoided at any cost - very fragile and non-transparent.
You can review the process of signing the binary from CPack cmake code, there should be more appropriate place for the code
| def _cgo_arch_flags(self, goarch): | ||
| return f"-arch {self._clang_arch_map[goarch]}" | ||
|
|
||
| def _build_go_arch(self, goarch): |
There was a problem hiding this comment.
I still have a complaint about the building process - there should be a single function which does the job.
I find trying to put something into the hooks a very bad practice. Recipe becomes unclear to read and analyze in the future
DRY KISS
| env.define(name, value) | ||
|
|
||
| def _go_arch_make_args(self, goarch): | ||
| return [f"{name}={value}" for name, value in self._go_cache_vars().items()] + [ |
There was a problem hiding this comment.
Looks like a slope. Why don't we just add them by env.define() calls?
Complex logic is not what we want here
KISS
| } | ||
|
|
||
| def _define_go_cache_env(self, env): | ||
| for name, value in self._go_cache_vars().items(): |
There was a problem hiding this comment.
Same for here. Why do we need all of those abstractions if we can define those vars in place at generate() stage?
KISS
| ) | ||
|
|
||
| def generate(self): | ||
| VirtualBuildEnv(self).generate() |
There was a problem hiding this comment.
All recipes have virtualbuildenv by default, if it's not turned off explicitly. Redundant; safe to remove
|
|
||
| def _build_go_arch(self, goarch): | ||
| autotools = Autotools(self) | ||
| autotools.make(args=self._go_arch_make_args(goarch)) |
There was a problem hiding this comment.
Subsequent calls of make with different arch could lead to UB. Make sure it's cleared or build in separate folders
| return str(self.settings.os) == "Macos" and len(self._archs) > 1 | ||
|
|
||
| @property | ||
| def _is_unsupported_multi_arch(self): |
There was a problem hiding this comment.
Property is overkill, could be inlined. KISS
| set(MACOS_CODE_SIGN_FLAGS "--deep") | ||
| endif() | ||
| set_target_properties(${PROJECT} PROPERTIES | ||
| XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "${MACOS_CODE_SIGN_FLAGS}" |
There was a problem hiding this comment.
Macos build could be assembled using not only the Xcode generator. I find this one an unreliable thing
| MACOSX_PACKAGE_LOCATION MacOS | ||
| ) | ||
| target_sources(${PROJECT} PRIVATE ${MACOS_OVPN_SCRIPT}) | ||
| if(BUILD_VPN_KEYCHAIN) |
There was a problem hiding this comment.
Why do we sign something during build? Please consider doing that in CPack as I mentioned previously. Or let's discuss that if you do not agree
| def _cgo_arch_flags(self, goarch): | ||
| return f"-arch {self._clang_arch_map[goarch]}" | ||
|
|
||
| def _build_go_arch(self, goarch): |
There was a problem hiding this comment.
This one is still unresolved
|
|
||
| def _build_go_arch(self, goarch): | ||
| autotools = Autotools(self) | ||
| autotools.make(args=self._go_arch_make_args(goarch)) |
| ${OVPN_SCRIPTS} | ||
| "$<TARGET_FILE_DIR:${PROJECT}>" | ||
| ) | ||
| if(NOT APPLE) |
There was a problem hiding this comment.
I assume on Apple it should be copied as well
|
|
||
| if (APPLE AND NOT IOS AND NOT MACOS_NE) | ||
| list(APPEND OVPN_SCRIPTS "${CMAKE_SOURCE_DIR}/deploy/data/macos/update-resolv-conf.sh") | ||
| set(MACOS_OVPN_SCRIPT "${CMAKE_SOURCE_DIR}/deploy/data/macos/update-resolv-conf.sh") |
There was a problem hiding this comment.
Do we really need this change? :D
Looks like we use an additional variable to store a single string in the list
| for goarch in self._goarchs: | ||
| arch_build_folder = os.path.join(self.build_folder, f"build-{goarch}") | ||
| rmdir(self, arch_build_folder) | ||
| copy(self, "*", src=self.source_folder, dst=arch_build_folder, excludes=( |
There was a problem hiding this comment.
Looks complicated and untrivial.
I would suggest to use DESTDIR variable of the original Makefile
| )) | ||
|
|
||
| at = Autotools(self) | ||
| with chdir(self, arch_build_folder): |
There was a problem hiding this comment.
This one ain't gonna work. To execute Makefile you have to be in the same directory with it, or use -C option. The 2nd could produce unexpected output
| env.define("GOOS", self._goos) | ||
| env.define("GOARCH", self._goarch) | ||
| if not self._is_universal_macos: | ||
| env.define("GOARCH", self._goarch) |
There was a problem hiding this comment.
You already define one in Makefile call itself. I do not think the extra one is required
| at = Autotools(self) | ||
| with chdir(self, arch_build_folder): | ||
| at.make(args=[ | ||
| f"GOOS={self._goos}", |
There was a problem hiding this comment.
I do not think multi-os bundles are possible :)
Let's stick with the only one defined in env
| tc.generate(env) | ||
|
|
||
| def build(self): | ||
| if self._is_universal_macos: |
There was a problem hiding this comment.
Still special handling in here.
Let's use a unified way to compile the binary despite the fact it is multiarch. The only difference is the merging thingy made by lipo
No description provided.