diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-19 16:19:01 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-19 16:19:01 +0200 |
| commit | abe3588e56850403f7ebaf3c9090552e5f4830c6 (patch) | |
| tree | 2e9301bed577ca3d711361f255df43cd46a097da | |
| parent | 5f2e7ef988ac1267fe5038419b19b0154f9d5a84 (diff) | |
Exports: Simplify building
- Remove subdir c
- Do not compile c code as a separate shared library
- Move all definitions/declarations into the preamble as they shouldn't be shared anyways. So no headers are needed
- Define the callback as static, needed so we don't get a duplicate declaration
| -rw-r--r-- | exports/Makefile | 10 | ||||
| -rw-r--r-- | exports/c/common.c | 6 | ||||
| -rw-r--r-- | exports/c/common.h | 3 | ||||
| -rw-r--r-- | exports/c/disco.h | 34 | ||||
| -rw-r--r-- | exports/c/servers.h | 44 | ||||
| -rw-r--r-- | exports/common.mk | 2 | ||||
| -rw-r--r-- | exports/disco.go | 35 | ||||
| -rw-r--r-- | exports/exports.go | 13 | ||||
| -rw-r--r-- | exports/servers.go | 45 |
9 files changed, 84 insertions, 108 deletions
diff --git a/exports/Makefile b/exports/Makefile index 46d17a9..1434f8b 100644 --- a/exports/Makefile +++ b/exports/Makefile @@ -2,8 +2,6 @@ include common.mk -CLIBPATH=./c - ifeq ($(LIB_SUFFIX),.so) # Add SONAME as cgo does not currently do this. Mostly for Android, see https://stackoverflow.com/a/48291044 export override CGO_LDFLAGS += -Wl,-soname,$(LIB_FILE) @@ -15,18 +13,12 @@ ifdef COPY_LIB_TO install $< -Dt $(COPY_LIB_TO) endif -${CLIBPATH}/libcommon$(LIB_SUFFIX): ${CLIBPATH}/common.c - $(CC) -c -Wall -Werror -fpic -o ${CLIBPATH}/common.o ${CLIBPATH}/common.c - $(CC) -shared -o $@ ${CLIBPATH}/common.o - # Build shared library and remove lib prefix (if any) from header name # GOOS and GOARCH envvars are set by common.mk # This extra target prevents unnecessary rebuild -lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): ${CLIBPATH}/libcommon$(LIB_SUFFIX) exports.go servers.go .. +lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): .. CGO_ENABLED=1 go build -o $@ -buildmode=c-shared . mv lib/$(GOOS)/$(GOARCH)/$(LIB_PREFIX)$(LIB_NAME).h lib/$(GOOS)/$(GOARCH)/$(LIB_NAME).h || true # Normalize header name clean: rm -rf ../exports/lib/* - rm -rf ${CLIBPATH}/common.o - rm -rf ${CLIBPATH}/libcommon.so diff --git a/exports/c/common.c b/exports/c/common.c deleted file mode 100644 index 425a459..0000000 --- a/exports/c/common.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "common.h" - -void call_callback(PythonCB callback, const char *name, int oldstate, int newstate, void* data) -{ - callback(name, oldstate, newstate, data); -} diff --git a/exports/c/common.h b/exports/c/common.h deleted file mode 100644 index 068ad4c..0000000 --- a/exports/c/common.h +++ /dev/null @@ -1,3 +0,0 @@ -typedef void (*PythonCB)(const char* name, int oldstate, int newstate, void* data); - -void call_callback(PythonCB callback, const char *name, int oldstate, int newstate, void* data); diff --git a/exports/c/disco.h b/exports/c/disco.h deleted file mode 100644 index 8fa07a4..0000000 --- a/exports/c/disco.h +++ /dev/null @@ -1,34 +0,0 @@ -// for size_t -#include <stddef.h> - -typedef struct discoveryServer { - const char* authentication_url_template; - const char* base_url; - const char* country_code; - const char* display_name; - const char* keyword_list; - const char** public_key_list; - size_t total_public_keys; - const char* server_type; - const char** support_contact; - size_t total_support_contact; -} discoveryServer; - -typedef struct discoveryServers { - unsigned long long int version; - discoveryServer** servers; - size_t total_servers; -} discoveryServers; - -typedef struct discoveryOrganization { - const char* display_name; - const char* org_id; - const char* secure_internet_home; - const char* keyword_list; -} discoveryOrganization; - -typedef struct discoveryOrganizations { - unsigned long long int version; - discoveryOrganization** organizations; - size_t total_organizations; -} discoveryOrganizations; diff --git a/exports/c/servers.h b/exports/c/servers.h deleted file mode 100644 index 1b6cca9..0000000 --- a/exports/c/servers.h +++ /dev/null @@ -1,44 +0,0 @@ -// for size_t -#include <stddef.h> - -// The struct for a single server profile -typedef struct serverProfile { - const char* id; - const char* display_name; - //const char* proto_list; - int default_gateway; -} serverProfile; - -// The struct for all server profiles -typedef struct serverProfiles { - int current; - serverProfile** profiles; - size_t total_profiles; -} serverProfiles; - -// The struct for server locations -typedef struct serverLocations { - const char** locations; - size_t total_locations; -} serverLocations; - -// The struct for a single server -typedef struct server { - const char* identifier; - const char* display_name; - const char* server_type; - const char* country_code; - const char** support_contact; - size_t total_support_contact; - serverProfiles* profiles; - unsigned long long int expire_time; -} server; - -// The struct for all servers -typedef struct servers { - server** custom_servers; - size_t total_custom; - server** institute_servers; - size_t total_institute; - server* secure_internet_server; -} servers; diff --git a/exports/common.mk b/exports/common.mk index 211d460..c1e2a7e 100644 --- a/exports/common.mk +++ b/exports/common.mk @@ -7,8 +7,6 @@ ifndef GOARCH export GOARCH := $(shell go env GOHOSTARCH) endif -CC = gcc - ifeq (windows,$(GOOS)) LIB_PREFIX ?= LIB_SUFFIX ?= .dll diff --git a/exports/disco.go b/exports/disco.go index a08f8ba..bd5a663 100644 --- a/exports/disco.go +++ b/exports/disco.go @@ -1,9 +1,40 @@ package main /* -// for free +// for free and size_t #include <stdlib.h> -#include "c/disco.h" + +typedef struct discoveryServer { + const char* authentication_url_template; + const char* base_url; + const char* country_code; + const char* display_name; + const char* keyword_list; + const char** public_key_list; + size_t total_public_keys; + const char* server_type; + const char** support_contact; + size_t total_support_contact; +} discoveryServer; + +typedef struct discoveryServers { + unsigned long long int version; + discoveryServer** servers; + size_t total_servers; +} discoveryServers; + +typedef struct discoveryOrganization { + const char* display_name; + const char* org_id; + const char* secure_internet_home; + const char* keyword_list; +} discoveryOrganization; + +typedef struct discoveryOrganizations { + unsigned long long int version; + discoveryOrganization** organizations; + size_t total_organizations; +} discoveryOrganizations; */ import "C" diff --git a/exports/exports.go b/exports/exports.go index 0144500..4f0b865 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -1,13 +1,14 @@ package main /* -#cgo CFLAGS: -I${SRCDIR}/c -#cgo LDFLAGS: -Wl,-rpath,${SRCDIR}/c -#cgo LDFLAGS: -L${SRCDIR}/c -#cgo LDFLAGS: -lcommon - #include <stdlib.h> -#include "c/common.h" + +typedef void (*PythonCB)(const char* name, int oldstate, int newstate, void* data); + +static void call_callback(PythonCB callback, const char *name, int oldstate, int newstate, void* data) +{ + callback(name, oldstate, newstate, data); +} */ import "C" diff --git a/exports/servers.go b/exports/servers.go index d33ac1f..2dfb14b 100644 --- a/exports/servers.go +++ b/exports/servers.go @@ -1,9 +1,50 @@ package main /* -// for free +// for free and size_t #include <stdlib.h> -#include "c/servers.h" + +// The struct for a single server profile +typedef struct serverProfile { + const char* id; + const char* display_name; + //const char* proto_list; + int default_gateway; +} serverProfile; + +// The struct for all server profiles +typedef struct serverProfiles { + int current; + serverProfile** profiles; + size_t total_profiles; +} serverProfiles; + +// The struct for server locations +typedef struct serverLocations { + const char** locations; + size_t total_locations; +} serverLocations; + +// The struct for a single server +typedef struct server { + const char* identifier; + const char* display_name; + const char* server_type; + const char* country_code; + const char** support_contact; + size_t total_support_contact; + serverProfiles* profiles; + unsigned long long int expire_time; +} server; + +// The struct for all servers +typedef struct servers { + server** custom_servers; + size_t total_custom; + server** institute_servers; + size_t total_institute; + server* secure_internet_server; +} servers; */ import "C" |
