2026-05-04 16:59:24 +02:00
|
|
|
from conan import ConanFile
|
|
|
|
|
from conan.errors import ConanInvalidConfiguration
|
|
|
|
|
from conan.tools.layout import basic_layout
|
|
|
|
|
from conan.tools.files import get, copy
|
2026-05-26 15:50:10 +03:00
|
|
|
from conan.tools.apple import XCRun
|
2026-05-04 16:59:24 +02:00
|
|
|
from conan.tools.gnu import Autotools, AutotoolsToolchain
|
|
|
|
|
|
|
|
|
|
import os
|
2026-05-26 15:50:10 +03:00
|
|
|
import shlex
|
2026-05-04 16:59:24 +02:00
|
|
|
|
2026-05-12 00:56:34 +03:00
|
|
|
|
2026-05-04 16:59:24 +02:00
|
|
|
class AwgGo(ConanFile):
|
|
|
|
|
name = "awg-go"
|
|
|
|
|
version = "0.2.16"
|
|
|
|
|
package_type = "application"
|
|
|
|
|
settings = "os", "arch"
|
2026-05-12 00:56:34 +03:00
|
|
|
_binary_name = "amneziawg-go"
|
2026-05-04 16:59:24 +02:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _goos(self):
|
|
|
|
|
return {
|
|
|
|
|
"Linux": "linux",
|
|
|
|
|
"Macos": "darwin",
|
|
|
|
|
"Windows": "windows"
|
|
|
|
|
}.get(str(self.settings.os))
|
|
|
|
|
|
|
|
|
|
@property
|
2026-05-12 00:56:34 +03:00
|
|
|
def _arch_map(self):
|
2026-05-04 16:59:24 +02:00
|
|
|
return {
|
|
|
|
|
"x86": "386",
|
|
|
|
|
"x86_64": "amd64",
|
|
|
|
|
"armv8": "arm64"
|
2026-05-12 00:56:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _archs(self):
|
|
|
|
|
return str(self.settings.arch).split("|")
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _goarch(self):
|
|
|
|
|
goarchs = [self._arch_map.get(arch) for arch in self._archs]
|
|
|
|
|
return goarchs[0] if len(goarchs) == 1 else None
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _goarchs(self):
|
|
|
|
|
return [self._arch_map.get(arch) for arch in self._archs]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def _is_universal_macos(self):
|
|
|
|
|
return str(self.settings.os) == "Macos" and len(self._archs) > 1
|
|
|
|
|
|
|
|
|
|
def _go_arch_make_args(self, goarch):
|
2026-05-29 13:56:19 +03:00
|
|
|
return [
|
2026-05-12 00:56:34 +03:00
|
|
|
f"GOOS={self._goos}",
|
|
|
|
|
f"GOARCH={goarch}",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def _build_go_arch(self, goarch):
|
|
|
|
|
autotools = Autotools(self)
|
2026-05-29 13:56:19 +03:00
|
|
|
autotools.make("clean")
|
2026-05-12 00:56:34 +03:00
|
|
|
autotools.make(args=self._go_arch_make_args(goarch))
|
|
|
|
|
|
|
|
|
|
output_path = os.path.join(self.build_folder, self._binary_name)
|
|
|
|
|
arch_output_path = os.path.join(self.build_folder, f"{self._binary_name}-{goarch}")
|
|
|
|
|
os.rename(output_path, arch_output_path)
|
|
|
|
|
return arch_output_path
|
|
|
|
|
|
|
|
|
|
def _build_universal_macos(self):
|
|
|
|
|
outputs = [self._build_go_arch(goarch) for goarch in self._goarchs]
|
|
|
|
|
universal_output = os.path.join(self.build_folder, self._binary_name)
|
2026-05-26 15:50:10 +03:00
|
|
|
lipo = XCRun(self).find("lipo")
|
|
|
|
|
self.run("{} -create {} -output {}".format(
|
|
|
|
|
shlex.quote(lipo),
|
|
|
|
|
" ".join(shlex.quote(output) for output in outputs),
|
|
|
|
|
shlex.quote(universal_output)
|
|
|
|
|
))
|
2026-05-04 16:59:24 +02:00
|
|
|
|
|
|
|
|
def layout(self):
|
|
|
|
|
basic_layout(self, build_folder=".")
|
|
|
|
|
|
|
|
|
|
def build_requirements(self):
|
|
|
|
|
self.tool_requires("go/1.26.0")
|
|
|
|
|
|
|
|
|
|
def validate(self):
|
2026-05-29 13:56:19 +03:00
|
|
|
if not self._goos or not all(self._goarchs) or (len(self._archs) > 1 and not self._is_universal_macos):
|
2026-05-04 16:59:24 +02:00
|
|
|
raise ConanInvalidConfiguration(
|
|
|
|
|
f"{self.name} v{self.version} does not support {self.settings.os} {self.settings.arch}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def source(self):
|
|
|
|
|
get(self, f"https://github.com/amnezia-vpn/amneziawg-go/archive/refs/tags/v{self.version}.zip",
|
|
|
|
|
sha256="34da7d4189f215f3930de441548bc2a0c89d54d347a4fb85cb9c715fce6413aa", strip_root=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
|
tc = AutotoolsToolchain(self)
|
|
|
|
|
env = tc.environment()
|
2026-05-29 13:56:19 +03:00
|
|
|
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")
|
2026-05-04 16:59:24 +02:00
|
|
|
env.define("GOOS", self._goos)
|
2026-05-12 00:56:34 +03:00
|
|
|
if not self._is_universal_macos:
|
|
|
|
|
env.define("GOARCH", self._goarch)
|
2026-05-04 16:59:24 +02:00
|
|
|
env.define("CGO_LDFLAGS", tc.ldflags)
|
|
|
|
|
env.define("CGO_CFLAGS", tc.cflags)
|
|
|
|
|
tc.generate(env)
|
|
|
|
|
|
|
|
|
|
def build(self):
|
2026-05-12 00:56:34 +03:00
|
|
|
if self._is_universal_macos:
|
|
|
|
|
self._build_universal_macos()
|
|
|
|
|
return
|
|
|
|
|
|
2026-05-04 16:59:24 +02:00
|
|
|
at = Autotools(self)
|
|
|
|
|
at.make()
|
|
|
|
|
|
|
|
|
|
def package(self):
|
2026-05-12 00:56:34 +03:00
|
|
|
copy(self, self._binary_name, src=self.build_folder, dst=self.package_folder)
|
2026-05-04 16:59:24 +02:00
|
|
|
|
|
|
|
|
def package_info(self):
|
|
|
|
|
self.cpp_info.exe = True
|
2026-05-12 00:56:34 +03:00
|
|
|
self.cpp_info.location = os.path.join(self.package_folder, self._binary_name)
|
2026-05-04 16:59:24 +02:00
|
|
|
self.cpp_info.set_property("cmake_target_name", "amnezia::awg-go")
|