github.com/Psiphon-Labs/tls-tris@v0.0.0-20230824155421-58bf6d336a9a/_dev/Makefile (about)

     1  # Constants
     2  MK_FILE_PATH = $(lastword $(MAKEFILE_LIST))
     3  PRJ_DIR      = $(abspath $(dir $(MK_FILE_PATH))/..)
     4  DEV_DIR      = $(PRJ_DIR)/_dev
     5  # Results will be produced in this directory (can be provided by a caller)
     6  BUILD_DIR   ?= $(PRJ_DIR)/_dev/GOROOT
     7  
     8  # Compiler
     9  GO ?= go
    10  DOCKER ?= docker
    11  
    12  # Build environment
    13  OS          ?= $(shell $(GO) env GOHOSTOS)
    14  ARCH        ?= $(shell $(GO) env GOHOSTARCH)
    15  OS_ARCH     := $(OS)_$(ARCH)
    16  VER_OS_ARCH := $(shell $(GO) version | cut -d' ' -f 3)_$(OS)_$(ARCH)
    17  GOROOT_ENV  := $(shell $(GO) env GOROOT)
    18  GOROOT_LOCAL = $(BUILD_DIR)/$(OS_ARCH)
    19  # Flag indicates wheter invoke "go install -race std". Supported only on amd64 with CGO enabled
    20  INSTALL_RACE:= $(words $(filter $(ARCH)_$(shell go env CGO_ENABLED), amd64_1))
    21  
    22  # Test targets used for compatibility testing
    23  TARGET_TEST_COMPAT=boring picotls tstclnt
    24  
    25  # Some target-specific constants
    26  BORINGSSL_REVISION=d451453067cd665a5c38830fbbaac9e599234a5e
    27  BOGO_DOCKER_TRIS_LOCATION=/go/src/github.com/cloudflare/tls-tris
    28  
    29  ###############
    30  #
    31  # Build targets
    32  #
    33  ##############################
    34  $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH): clean
    35  
    36  # Create clean directory structure
    37  	mkdir -p "$(GOROOT_LOCAL)/pkg"
    38  
    39  # Copy src/tools from system GOROOT
    40  	cp -Hr $(GOROOT_ENV)/src $(GOROOT_LOCAL)/src
    41  	cp -Hr $(GOROOT_ENV)/pkg/include $(GOROOT_LOCAL)/pkg/include
    42  	cp -Hr $(GOROOT_ENV)/pkg/tool $(GOROOT_LOCAL)/pkg/tool
    43  
    44  # Swap TLS implementation
    45  	rm -r $(GOROOT_LOCAL)/src/crypto/tls/*
    46  	rsync -rltgoD $(PRJ_DIR)/ $(GOROOT_LOCAL)/src/crypto/tls/ --exclude=$(lastword $(subst /, ,$(DEV_DIR)))
    47  
    48  # Apply additional patches
    49  	for p in $(wildcard $(DEV_DIR)/patches/*); do patch -d "$(GOROOT_LOCAL)" -p1 < "$$p"; done
    50  
    51  # Create go package
    52  	GOARCH=$(ARCH) GOROOT="$(GOROOT_LOCAL)" $(GO) install -v std
    53  ifeq ($(INSTALL_RACE),1)
    54  	GOARCH=$(ARCH) GOROOT="$(GOROOT_LOCAL)" $(GO) install -race -v std
    55  endif
    56  	@touch "$@"
    57  
    58  build-test-%: $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
    59  	$(DOCKER) build $(BUILDARG) -t tls-tris:$* $(DEV_DIR)/$*
    60  	$(DOCKER) build $(BUILDARG) -t $(*)-localserver $(DEV_DIR)/$*
    61  
    62  build-all: \
    63  	build-test-tris-client \
    64  	build-test-tris-server \
    65  	build-test-bogo \
    66  	$(addprefix build-test-,$(TARGET_TEST_COMPAT))
    67  
    68  # Builds TRIS client
    69  build-test-tris-client: $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
    70  	cd $(DEV_DIR)/tris-testclient; CGO_ENABLED=0 GOROOT="$(GOROOT_LOCAL)" $(GO) build -v -i .
    71  	$(DOCKER) build -t tris-testclient $(DEV_DIR)/tris-testclient
    72  
    73  # Builds TRIS server
    74  build-test-tris-server: $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
    75  	cd $(DEV_DIR)/tris-localserver; CGO_ENABLED=0 GOROOT="$(GOROOT_LOCAL)" $(GO) build -v -i .
    76  	$(DOCKER) build -t tris-localserver $(DEV_DIR)/tris-localserver
    77  
    78  # BoringSSL specific stuff
    79  build-test-boring: 	BUILDARG=--build-arg REVISION=$(BORINGSSL_REVISION)
    80  
    81  # TODO: This probably doesn't work
    82  build-caddy: $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
    83  	CGO_ENABLED=0 GOROOT="$(GOROOT_LOCAL)" $(GO) build github.com/mholt/caddy
    84  
    85  ###############
    86  #
    87  # Test targets
    88  #
    89  ##############################
    90  test: \
    91  	test-unit \
    92  	test-bogo \
    93  	test-interop
    94  
    95  test-unit: $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
    96  	GOROOT="$(GOROOT_LOCAL)" $(GO) test -race crypto/tls
    97  
    98  test-bogo:
    99  	$(DOCKER) run --rm -v $(PRJ_DIR):$(BOGO_DOCKER_TRIS_LOCATION) tls-tris:bogo
   100  
   101  test-interop:
   102  	$(DEV_DIR)/interop_test_runner -v
   103  
   104  ###############
   105  #
   106  # Utils
   107  #
   108  ##############################
   109  clean:
   110  	rm -rf $(BUILD_DIR)/$(OS_ARCH)
   111  
   112  clean-all: clean
   113  	rm -rf $(BUILD_DIR)
   114  
   115  fmtcheck:
   116  	$(DEV_DIR)/utils/fmtcheck.sh
   117  
   118  .PHONY: $(BUILD_DIR) clean build build-test test test-unit test-bogo test-interop