Skip to content

Commit 3a92566

Browse files
authored
Support cross-compilation for use with Nerves (#1543)
1 parent 21d9d4a commit 3a92566

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

exla/Makefile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,28 @@ endif
4040

4141
LDFLAGS = -L$(XLA_EXTENSION_LIB) -lxla_extension -shared
4242

43-
ifeq ($(shell uname -s), Darwin)
43+
ifeq ($(CROSSCOMPILE),)
44+
# Interrogate the system for local compilation
45+
UNAME_S = $(shell uname -s)
46+
47+
NVCC_RESULT := $(shell which nvcc 2> /dev/null)
48+
NVCC_TEST := $(notdir $(NVCC_RESULT))
49+
50+
ifeq ($(NVCC_TEST),nvcc)
51+
NVCC := nvcc
52+
NVCCFLAGS += -DCUDA_ENABLED
53+
else
54+
NVCC := $(CXX)
55+
NVCCFLAGS = $(CFLAGS)
56+
endif
57+
else
58+
# Determine settings for cross-compiled builds like for Nerves
59+
UNAME_S = Linux
60+
NVCC := $(CXX)
61+
NVCCFLAGS = $(CFLAGS)
62+
endif
63+
64+
ifeq ($(UNAME_S), Darwin)
4465
LDFLAGS += -flat_namespace -undefined dynamic_lookup -rpath @loader_path/xla_extension/lib
4566
else
4667
# Use a relative RPATH, so at runtime libexla.so looks for libxla_extension.so
@@ -67,17 +88,6 @@ HEADERS = $(EXLA_DIR)/exla_mlir.h $(EXLA_DIR)/custom_calls/qr.h $(EXLA_DIR)/cust
6788
OBJECTS = $(patsubst $(EXLA_DIR)/%.cc,$(EXLA_CACHE_OBJ_DIR)/%.o,$(SOURCES)) $(EXLA_CACHE_OBJ_DIR)/exla_cuda.o
6889

6990

70-
NVCC_RESULT := $(shell which nvcc 2> /dev/null)
71-
NVCC_TEST := $(notdir $(NVCC_RESULT))
72-
73-
ifeq ($(NVCC_TEST),nvcc)
74-
NVCC := nvcc
75-
NVCCFLAGS += -DCUDA_ENABLED
76-
else
77-
NVCC := $(CXX)
78-
NVCCFLAGS = $(CFLAGS)
79-
endif
80-
8191
$(EXLA_CACHE_OBJ_DIR)/exla_cuda.o: $(EXLA_DIR)/exla_cuda.cc $(EXLA_DIR)/exla_cuda.h
8292
@ mkdir -p $(EXLA_CACHE_OBJ_DIR)
8393
$(NVCC) $(NVCCFLAGS) -c $< -o $@

0 commit comments

Comments
 (0)