mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
conan: beautify makefile-based recipes
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
# conanfile.py
|
||||
from conan import ConanFile
|
||||
from conan.tools.files import get, copy, collect_libs
|
||||
from conan.tools.files import get, copy, collect_libs, chdir
|
||||
from conan.tools.layout import basic_layout
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.gnu import Autotools, AutotoolsToolchain
|
||||
from conan.tools.env import Environment
|
||||
|
||||
import os
|
||||
|
||||
@@ -12,47 +14,59 @@ class AmneziaXrayBindings(ConanFile):
|
||||
|
||||
settings = "os", "arch"
|
||||
|
||||
_os_map = {
|
||||
"Linux": "linux",
|
||||
"iOS": "ios",
|
||||
"Macos": "macos",
|
||||
"Windows": "windows"
|
||||
}
|
||||
_arch_map = {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64",
|
||||
}
|
||||
@property
|
||||
def _goos(self):
|
||||
return {
|
||||
"Linux": "linux",
|
||||
"iOS": "ios",
|
||||
"Macos": "darwin",
|
||||
"Windows": "windows"
|
||||
}.get(str(self.settings.os))
|
||||
|
||||
@property
|
||||
def _goarch(self):
|
||||
return {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64"
|
||||
}.get(str(self.settings.arch))
|
||||
|
||||
@property
|
||||
def _is_windows(self):
|
||||
return str(self.settings.os).startswith("Windows")
|
||||
|
||||
def validate(self):
|
||||
self._goos = self._os_map.get(str(self.settings.os))
|
||||
if not self._goos:
|
||||
if not self._goos or not self._goarch:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {self._goos}"
|
||||
)
|
||||
|
||||
self._goarch = self._arch_map.get(str(self.settings.arch))
|
||||
if not self._goarch:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {self._goarch}"
|
||||
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
|
||||
)
|
||||
|
||||
def layout(self):
|
||||
basic_layout(self, build_folder=".")
|
||||
basic_layout(self)
|
||||
|
||||
def build_requirements(self):
|
||||
self.tool_requires("go/1.26.0")
|
||||
if self.settings.os == "Windows":
|
||||
self.tool_requires("mingw-builds/15.1.0")
|
||||
else:
|
||||
self.build_requires("make/4.4.1")
|
||||
|
||||
def source(self):
|
||||
get(self, "https://github.com/amnezia-vpn/amnezia-xray-bindings/archive/v1.1.0.zip",
|
||||
sha256="6ea768ec7002cedd422a39aea17704b888acaf794432aa5937cfc92fb6d80eb5", strip_root=True)
|
||||
|
||||
def generate(self):
|
||||
tc = AutotoolsToolchain(self)
|
||||
env = Environment()
|
||||
env.define("ARCH", self._goarch)
|
||||
env.define("GOARCH", self._goarch)
|
||||
env.define("GOOS", self._goos)
|
||||
env.define("CGO_LDFLAGS", tc.ldflags)
|
||||
env.define("CGO_CFLAGS", tc.cflags)
|
||||
if self._is_windows:
|
||||
env.define("OS", "windows")
|
||||
tc.generate(env)
|
||||
|
||||
def build(self):
|
||||
self.run(f"ARCH={self._goarch} OS={self._goos} make -C {self.source_folder}")
|
||||
with chdir(self, self.source_folder):
|
||||
autotools = Autotools(self)
|
||||
autotools.make()
|
||||
|
||||
def _rename_libs(self):
|
||||
# workaround of bad naming strategy in amnezia-xray-bindings
|
||||
@@ -65,10 +79,10 @@ class AmneziaXrayBindings(ConanFile):
|
||||
os.rename(src, dst)
|
||||
|
||||
def package(self):
|
||||
copy(self, "*.h", src=self.build_folder, dst=os.path.join(self.package_folder, "include"), keep_path=False)
|
||||
copy(self, "*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
|
||||
copy(self, "*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
|
||||
copy(self, "*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
|
||||
copy(self, "*.h", src=self.build_folder, dst=os.path.join(self.package_folder, "include"))
|
||||
copy(self, "*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"))
|
||||
copy(self, "*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"))
|
||||
copy(self, "*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"))
|
||||
self._rename_libs()
|
||||
|
||||
def package_info(self):
|
||||
|
||||
@@ -7,12 +7,9 @@ from conan.tools.gnu import AutotoolsToolchain, Autotools
|
||||
|
||||
import os
|
||||
|
||||
_uniarch_separator = "|"
|
||||
|
||||
class AwgApple(ConanFile):
|
||||
name = "awg-apple"
|
||||
version = "2.0.1"
|
||||
|
||||
settings = "os", "arch"
|
||||
options = {
|
||||
"as_framework": [True, False]
|
||||
@@ -22,12 +19,12 @@ class AwgApple(ConanFile):
|
||||
}
|
||||
|
||||
@property
|
||||
def goarch(self):
|
||||
def _goarch(self):
|
||||
arch_map = {
|
||||
"armv8": "arm64",
|
||||
"x86_64": "x86_64",
|
||||
}
|
||||
archs = str(self.settings.arch).split(_uniarch_separator)
|
||||
archs = str(self.settings.arch).split("|")
|
||||
return " ".join(arch_map.get(arch, arch) for arch in archs)
|
||||
|
||||
def build_requirements(self):
|
||||
@@ -51,7 +48,7 @@ class AwgApple(ConanFile):
|
||||
tc = AutotoolsToolchain(self)
|
||||
sdk = self.settings.get_safe("os.sdk", "macosx")
|
||||
tc.make_args = [
|
||||
f"ARCHS={self.goarch}",
|
||||
f"ARCHS={self._goarch}",
|
||||
f"PLATFORM_NAME={sdk}"
|
||||
]
|
||||
tc.generate()
|
||||
|
||||
@@ -2,6 +2,8 @@ from conan import ConanFile
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.layout import basic_layout
|
||||
from conan.tools.files import get, copy
|
||||
from conan.tools.gnu import Autotools, AutotoolsToolchain
|
||||
from conan.tools.env import Environment
|
||||
|
||||
import os
|
||||
|
||||
@@ -9,38 +11,31 @@ class AwgGo(ConanFile):
|
||||
name = "awg-go"
|
||||
version = "0.2.16"
|
||||
package_type = "application"
|
||||
|
||||
settings = "os", "arch"
|
||||
|
||||
_os_map = {
|
||||
"Linux": "linux",
|
||||
"Macos": "darwin",
|
||||
"Windows": "windows"
|
||||
}
|
||||
_arch_map = {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64",
|
||||
}
|
||||
@property
|
||||
def _goos(self):
|
||||
return {
|
||||
"Linux": "linux",
|
||||
"Macos": "darwin",
|
||||
"Windows": "windows"
|
||||
}.get(str(self.settings.os))
|
||||
|
||||
@property
|
||||
def _goarch(self):
|
||||
return {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64"
|
||||
}.get(str(self.settings.arch))
|
||||
|
||||
def build_requirements(self):
|
||||
self.tool_requires("go/1.26.0")
|
||||
if self.settings.os == "Windows":
|
||||
self.tool_requires("mingw-builds/15.1.0")
|
||||
else:
|
||||
self.build_requires("make/4.4.1")
|
||||
|
||||
def validate(self):
|
||||
os = str(self.settings.os)
|
||||
if os not in self._os_map:
|
||||
if not self._goos or not self._goarch:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {os}"
|
||||
)
|
||||
|
||||
arch = str(self.settings.arch)
|
||||
if arch not in self._arch_map:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {arch}"
|
||||
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
|
||||
)
|
||||
|
||||
def source(self):
|
||||
@@ -51,11 +46,16 @@ class AwgGo(ConanFile):
|
||||
def layout(self):
|
||||
basic_layout(self, build_folder=".")
|
||||
|
||||
def build(self):
|
||||
os = self._os_map[str(self.settings.os)]
|
||||
arch = self._arch_map[str(self.settings.arch)]
|
||||
def generate(self):
|
||||
tc = AutotoolsToolchain(self)
|
||||
env = Environment()
|
||||
env.define("GOOS", self._goos)
|
||||
env.define("GOARCH", self._goarch)
|
||||
tc.generate(env)
|
||||
|
||||
self.run(f"GOOS={os} GOARCH={arch} make")
|
||||
def build(self):
|
||||
at = Autotools(self)
|
||||
at.make()
|
||||
|
||||
def package(self):
|
||||
copy(self, "amneziawg-go", src=self.build_folder, dst=self.package_folder)
|
||||
@@ -63,5 +63,4 @@ class AwgGo(ConanFile):
|
||||
def package_info(self):
|
||||
self.cpp_info.exe = True
|
||||
self.cpp_info.location = os.path.join(self.package_folder, "amneziawg-go")
|
||||
|
||||
self.cpp_info.set_property("cmake_target_name", "amnezia::awg-go")
|
||||
|
||||
@@ -6,7 +6,6 @@ from conan.internal.model.pkg_type import PackageType
|
||||
from conan.tools.gnu import AutotoolsToolchain, Autotools
|
||||
from conan.tools.apple import is_apple_os
|
||||
|
||||
import platform
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ class Openvpn(ConanFile):
|
||||
name = "openvpn"
|
||||
version = "2.7.0"
|
||||
package_type = "application"
|
||||
|
||||
settings = "os", "build_type", "arch"
|
||||
|
||||
def layout(self):
|
||||
|
||||
@@ -14,14 +14,17 @@ class OpenVPNAdapter(ConanFile):
|
||||
version = "1.0.0"
|
||||
settings = "os", "build_type"
|
||||
|
||||
@property
|
||||
def _sdk(self):
|
||||
return str(self.settings.get_safe("os.sdk", "macosx"))
|
||||
|
||||
@property
|
||||
def _platform(self):
|
||||
sdk = self.settings.get_safe("os.sdk", "macosx")
|
||||
return {
|
||||
"macosx": "macOS",
|
||||
"iphoneos": "iOS",
|
||||
"iphonesimulator": "iOS Simulator"
|
||||
}.get(sdk)
|
||||
}.get(self._sdk)
|
||||
|
||||
@property
|
||||
def _configuration(self):
|
||||
@@ -45,14 +48,13 @@ class OpenVPNAdapter(ConanFile):
|
||||
)
|
||||
|
||||
def build(self):
|
||||
sdk = self.settings.get_safe("os.sdk", "macosx")
|
||||
with chdir(self, self.source_folder):
|
||||
self.run("xcrun xcodebuild"
|
||||
" -project OpenVPNAdapter.xcodeproj"
|
||||
" -scheme OpenVPNAdapter"
|
||||
" -configuration Release"
|
||||
f" -destination 'generic/platform={self._platform}'"
|
||||
f" -sdk {sdk}"
|
||||
f" -sdk {self._sdk}"
|
||||
f' "CONFIGURATION_BUILD_DIR={self.build_folder}"'
|
||||
f' "BUILT_PRODUCTS_DIR={self.build_folder}"'
|
||||
" BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
|
||||
|
||||
@@ -1,73 +1,80 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.layout import basic_layout
|
||||
from conan.tools.files import get, copy
|
||||
from conan.tools.files import get, copy, chdir
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
from conan.tools.gnu import Autotools, AutotoolsToolchain
|
||||
from conan.tools.env import Environment
|
||||
|
||||
import os
|
||||
|
||||
class Tun2Socks(ConanFile):
|
||||
name = "tun2socks"
|
||||
version = "2.6.0"
|
||||
|
||||
package_type = "application"
|
||||
settings = "os", "arch"
|
||||
|
||||
_os_map = {
|
||||
"Linux": "linux",
|
||||
"Macos": "darwin",
|
||||
"Windows": "windows"
|
||||
}
|
||||
_arch_map = {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64",
|
||||
}
|
||||
@property
|
||||
def _goos(self):
|
||||
return {
|
||||
"Linux": "linux",
|
||||
"Macos": "darwin",
|
||||
"Windows": "windows"
|
||||
}.get(str(self.settings.os))
|
||||
|
||||
@property
|
||||
def _goarch(self):
|
||||
return {
|
||||
"x86": "386",
|
||||
"x86_64": "amd64",
|
||||
"armv8": "arm64"
|
||||
}.get(str(self.settings.arch))
|
||||
|
||||
@property
|
||||
def _is_windows(self):
|
||||
return str(self.settings.get_safe("os")).startswith("Windows")
|
||||
|
||||
@property
|
||||
def _ext(self):
|
||||
return ".exe" if self._is_windows else ""
|
||||
|
||||
def layout(self):
|
||||
basic_layout(self)
|
||||
|
||||
def validate(self):
|
||||
if not self._goos or not self._goarch:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
|
||||
)
|
||||
|
||||
def build_requirements(self):
|
||||
self.tool_requires("go/1.26.0")
|
||||
if self.settings.os == "Windows":
|
||||
self.tool_requires("mingw-builds/15.1.0")
|
||||
else:
|
||||
self.build_requires("make/4.4.1")
|
||||
|
||||
def source(self):
|
||||
#TODO: get tunnel.dll for windows
|
||||
get(self, f"https://github.com/xjasonlyu/tun2socks/archive/refs/tags/v{self.version}.zip",
|
||||
sha256="a7ef9cec1c30dfe9971af89a8aac767fd3d2a4df833e92b635642c2f0204c701", strip_root=True
|
||||
)
|
||||
|
||||
def configure(self):
|
||||
self._goos = self._os_map.get(str(self.settings.os))
|
||||
if not self._goos:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {self._goos}"
|
||||
)
|
||||
|
||||
self._goarch = self._arch_map.get(str(self.settings.arch))
|
||||
if not self._goarch:
|
||||
raise ConanInvalidConfiguration(
|
||||
f"{self.name} v{self.version} does not support {self._goarch}"
|
||||
)
|
||||
|
||||
self._ext = ".exe" if self.settings.os == "Windows" else ""
|
||||
|
||||
def layout(self):
|
||||
basic_layout(self, build_folder=".")
|
||||
def generate(self):
|
||||
tc = AutotoolsToolchain(self)
|
||||
env = Environment()
|
||||
env.define("CGO_LDFLAGS", tc.ldflags)
|
||||
env.define("CGO_CFLAGS", tc.cflags)
|
||||
env.define("GOOS", self._goos)
|
||||
env.define("GOARCH", self._goarch)
|
||||
tc.generate(env)
|
||||
|
||||
def build(self):
|
||||
self.run(f"make {self._goos}-{self._goarch}")
|
||||
with chdir(self, self.source_folder):
|
||||
at = Autotools(self)
|
||||
at.make("tun2socks")
|
||||
|
||||
def package(self):
|
||||
src_name = f"tun2socks-{self._goos}-{self._goarch}{self._ext}"
|
||||
dst_name = f"tun2socks{self._ext}"
|
||||
|
||||
copy(self, src_name, src=os.path.join(self.build_folder, "build"), dst=self.package_folder)
|
||||
os.rename(
|
||||
os.path.join(self.package_folder, src_name),
|
||||
os.path.join(self.package_folder, dst_name)
|
||||
)
|
||||
copy(self, "tun2socks", src=self.build_folder, dst=self.package_folder)
|
||||
if self._is_windows:
|
||||
with chdir(self, self.package_folder):
|
||||
os.rename(src="tun2socks", dst="tun2socks.exe")
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.exe = True
|
||||
self.cpp_info.location = os.path.join(self.package_folder, f"tun2socks{self._ext}")
|
||||
|
||||
self.cpp_info.set_property("cmake_target_name", "xjasonlyu::tun2socks")
|
||||
|
||||
Reference in New Issue
Block a user