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
+15 -19
View File
@@ -239,36 +239,32 @@ install(SCRIPT ${QT_DEPLOY_SCRIPT}
) )
if (APPLE AND NOT IOS AND NOT MACOS_NE) 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() endif()
if (LINUX AND NOT ANDROID) if (LINUX AND NOT ANDROID)
list(APPEND OVPN_SCRIPTS "${CMAKE_SOURCE_DIR}/deploy/data/linux/update-resolv-conf.sh") list(APPEND OVPN_SCRIPTS "${CMAKE_SOURCE_DIR}/deploy/data/linux/update-resolv-conf.sh")
endif() endif()
if(OVPN_SCRIPTS) if(OVPN_SCRIPTS)
if(NOT APPLE)
add_custom_command(TARGET ${PROJECT} POST_BUILD add_custom_command(TARGET ${PROJECT} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
${OVPN_SCRIPTS} ${OVPN_SCRIPTS}
"$<TARGET_FILE_DIR:${PROJECT}>" "$<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
]=])
add_custom_command(TARGET ${PROJECT} POST_BUILD
COMMAND /bin/sh -c "${SIGN_OVPN_SCRIPT}" _ "$<TARGET_FILE_DIR:${PROJECT}>/update-resolv-conf.sh"
VERBATIM
)
endif() endif()
install(FILES ${OVPN_SCRIPTS} install(FILES ${OVPN_SCRIPTS}
+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.files import get, copy
from conan.tools.apple import XCRun from conan.tools.apple import XCRun
from conan.tools.gnu import Autotools, AutotoolsToolchain from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.env import VirtualBuildEnv
import os import os
import shlex import shlex
@@ -50,30 +49,15 @@ class AwgGo(ConanFile):
def _is_universal_macos(self): def _is_universal_macos(self):
return str(self.settings.os) == "Macos" and len(self._archs) > 1 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): 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"GOOS={self._goos}",
f"GOARCH={goarch}", f"GOARCH={goarch}",
] ]
def _build_go_arch(self, goarch): def _build_go_arch(self, goarch):
autotools = Autotools(self) autotools = Autotools(self)
autotools.make("clean")
autotools.make(args=self._go_arch_make_args(goarch)) autotools.make(args=self._go_arch_make_args(goarch))
output_path = os.path.join(self.build_folder, self._binary_name) 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") self.tool_requires("go/1.26.0")
def validate(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( raise ConanInvalidConfiguration(
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}" 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): def generate(self):
VirtualBuildEnv(self).generate()
tc = AutotoolsToolchain(self) tc = AutotoolsToolchain(self)
env = tc.environment() 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) env.define("GOOS", self._goos)
if not self._is_universal_macos: if not self._is_universal_macos:
env.define("GOARCH", self._goarch) 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.errors import ConanInvalidConfiguration
from conan.tools.apple import XCRun from conan.tools.apple import XCRun
from conan.tools.gnu import Autotools, AutotoolsToolchain from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.env import VirtualBuildEnv
import os import os
import shlex import shlex
@@ -50,32 +49,24 @@ class Tun2Socks(ConanFile):
def _is_universal_macos(self): def _is_universal_macos(self):
return str(self.settings.os) == "Macos" and len(self._archs) > 1 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): def _go_arch_make_args(self, goarch):
return [f"{name}={value}" for name, value in self._go_cache_vars().items()] + [ return [
"LDFLAGS=", "LDFLAGS=",
f"GOOS={self._goos}", f"GOOS={self._goos}",
f"GOARCH={goarch}", f"GOARCH={goarch}",
] ]
def _build_go_arch(self, goarch): def _build_go_arch(self, goarch):
with chdir(self, self.source_folder):
autotools = Autotools(self) 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.make(self._binary_name, args=self._go_arch_make_args(goarch)) autotools.make(self._binary_name, args=self._go_arch_make_args(goarch))
output_path = os.path.join(self.build_folder, self._binary_name) output_path = os.path.join(self.build_folder, self._binary_name)
@@ -110,7 +101,7 @@ class Tun2Socks(ConanFile):
basic_layout(self) basic_layout(self)
def validate(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( raise ConanInvalidConfiguration(
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}" 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): def generate(self):
VirtualBuildEnv(self).generate()
tc = AutotoolsToolchain(self) tc = AutotoolsToolchain(self)
env = tc.environment() 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("LDFLAGS", "")
env.define("CGO_LDFLAGS", tc.ldflags) env.define("CGO_LDFLAGS", tc.ldflags)
env.define("CGO_CFLAGS", tc.cflags) env.define("CGO_CFLAGS", tc.cflags)