Address macOS build review comments

This commit is contained in:
spectrum
2026-05-29 13:56:19 +03:00
parent 6e7925b534
commit c9befdfaad
3 changed files with 40 additions and 65 deletions
+18 -22
View File
@@ -239,35 +239,31 @@ install(SCRIPT ${QT_DEPLOY_SCRIPT}
)
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")
list(APPEND OVPN_SCRIPTS ${MACOS_OVPN_SCRIPT})
set_source_files_properties(${MACOS_OVPN_SCRIPT} PROPERTIES
MACOSX_PACKAGE_LOCATION MacOS
)
target_sources(${PROJECT} PRIVATE ${MACOS_OVPN_SCRIPT})
if(BUILD_VPN_KEYCHAIN)
set(MACOS_CODE_SIGN_FLAGS "--keychain ${BUILD_VPN_KEYCHAIN} --deep")
else()
set(MACOS_CODE_SIGN_FLAGS "--deep")
endif()
set_target_properties(${PROJECT} PROPERTIES
XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "${MACOS_CODE_SIGN_FLAGS}"
)
endif()
if (LINUX AND NOT ANDROID)
list(APPEND OVPN_SCRIPTS "${CMAKE_SOURCE_DIR}/deploy/data/linux/update-resolv-conf.sh")
endif()
if(OVPN_SCRIPTS)
add_custom_command(TARGET ${PROJECT} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${OVPN_SCRIPTS}
"$<TARGET_FILE_DIR:${PROJECT}>"
)
if(APPLE AND NOT IOS AND NOT MACOS_NE)
set(SIGN_OVPN_SCRIPT [=[
if [ "$CODE_SIGNING_ALLOWED" != "NO" ]; then
identity="$EXPANDED_CODE_SIGN_IDENTITY"
if [ -z "$identity" ]; then
identity="$CODE_SIGN_IDENTITY"
fi
if [ -z "$identity" ]; then
identity="-"
fi
/usr/bin/codesign --force --sign "$identity" "$1"
fi
]=])
if(NOT APPLE)
add_custom_command(TARGET ${PROJECT} POST_BUILD
COMMAND /bin/sh -c "${SIGN_OVPN_SCRIPT}" _ "$<TARGET_FILE_DIR:${PROJECT}>/update-resolv-conf.sh"
VERBATIM
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${OVPN_SCRIPTS}
"$<TARGET_FILE_DIR:${PROJECT}>"
)
endif()
+7 -21
View File
@@ -4,7 +4,6 @@ from conan.tools.layout import basic_layout
from conan.tools.files import get, copy
from conan.tools.apple import XCRun
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.env import VirtualBuildEnv
import os
import shlex
@@ -50,30 +49,15 @@ class AwgGo(ConanFile):
def _is_universal_macos(self):
return str(self.settings.os) == "Macos" and len(self._archs) > 1
@property
def _is_unsupported_multi_arch(self):
return len(self._archs) > 1 and not self._is_universal_macos
def _go_cache_vars(self):
return {
"GOPATH": os.path.join(self.build_folder, "gopath"),
"GOMODCACHE": os.path.join(self.build_folder, "gopath", "pkg", "mod"),
"GOCACHE": os.path.join(self.build_folder, "gocache"),
"GOTELEMETRY": "off",
}
def _define_go_cache_env(self, env):
for name, value in self._go_cache_vars().items():
env.define(name, value)
def _go_arch_make_args(self, goarch):
return [f"{name}={value}" for name, value in self._go_cache_vars().items()] + [
return [
f"GOOS={self._goos}",
f"GOARCH={goarch}",
]
def _build_go_arch(self, goarch):
autotools = Autotools(self)
autotools.make("clean")
autotools.make(args=self._go_arch_make_args(goarch))
output_path = os.path.join(self.build_folder, self._binary_name)
@@ -98,7 +82,7 @@ class AwgGo(ConanFile):
self.tool_requires("go/1.26.0")
def validate(self):
if not self._goos or not all(self._goarchs) or self._is_unsupported_multi_arch:
if not self._goos or not all(self._goarchs) or (len(self._archs) > 1 and not self._is_universal_macos):
raise ConanInvalidConfiguration(
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
)
@@ -109,10 +93,12 @@ class AwgGo(ConanFile):
)
def generate(self):
VirtualBuildEnv(self).generate()
tc = AutotoolsToolchain(self)
env = tc.environment()
self._define_go_cache_env(env)
env.define("GOPATH", os.path.join(self.build_folder, "gopath"))
env.define("GOMODCACHE", os.path.join(self.build_folder, "gopath", "pkg", "mod"))
env.define("GOCACHE", os.path.join(self.build_folder, "gocache"))
env.define("GOTELEMETRY", "off")
env.define("GOOS", self._goos)
if not self._is_universal_macos:
env.define("GOARCH", self._goarch)
+15 -22
View File
@@ -4,7 +4,6 @@ from conan.tools.files import get, copy, chdir
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import XCRun
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.env import VirtualBuildEnv
import os
import shlex
@@ -50,32 +49,24 @@ class Tun2Socks(ConanFile):
def _is_universal_macos(self):
return str(self.settings.os) == "Macos" and len(self._archs) > 1
@property
def _is_unsupported_multi_arch(self):
return len(self._archs) > 1 and not self._is_universal_macos
def _go_cache_vars(self):
return {
"GOPATH": os.path.join(self.build_folder, "gopath"),
"GOMODCACHE": os.path.join(self.build_folder, "gopath", "pkg", "mod"),
"GOCACHE": os.path.join(self.build_folder, "gocache"),
"GOTELEMETRY": "off",
}
def _define_go_cache_env(self, env):
for name, value in self._go_cache_vars().items():
env.define(name, value)
def _go_arch_make_args(self, goarch):
return [f"{name}={value}" for name, value in self._go_cache_vars().items()] + [
return [
"LDFLAGS=",
f"GOOS={self._goos}",
f"GOARCH={goarch}",
]
def _build_go_arch(self, goarch):
autotools = Autotools(self)
for output_path in (
os.path.join(self.build_folder, self._binary_name),
os.path.join(self.source_folder, self._binary_name),
os.path.join(self.source_folder, "build", self._binary_name),
):
if os.path.exists(output_path):
os.remove(output_path)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.make(self._binary_name, args=self._go_arch_make_args(goarch))
output_path = os.path.join(self.build_folder, self._binary_name)
@@ -110,7 +101,7 @@ class Tun2Socks(ConanFile):
basic_layout(self)
def validate(self):
if not self._goos or not all(self._goarchs) or self._is_unsupported_multi_arch:
if not self._goos or not all(self._goarchs) or (len(self._archs) > 1 and not self._is_universal_macos):
raise ConanInvalidConfiguration(
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
)
@@ -133,10 +124,12 @@ class Tun2Socks(ConanFile):
)
def generate(self):
VirtualBuildEnv(self).generate()
tc = AutotoolsToolchain(self)
env = tc.environment()
self._define_go_cache_env(env)
env.define("GOPATH", os.path.join(self.build_folder, "gopath"))
env.define("GOMODCACHE", os.path.join(self.build_folder, "gopath", "pkg", "mod"))
env.define("GOCACHE", os.path.join(self.build_folder, "gocache"))
env.define("GOTELEMETRY", "off")
env.define("LDFLAGS", "")
env.define("CGO_LDFLAGS", tc.ldflags)
env.define("CGO_CFLAGS", tc.cflags)