Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Elixir 1.8 + Nerves issues #75

Description

@ConnorRigby

With the introduction of Elixir 1.8, Mix.target() was added. This had the side effect of breaking packages that build C code that is not built by an updated version of elixir_make including this project's dependency on esqlite. esqlite is built by pc (port compiler, a rebar3 plugin). I believe it is unreasonable to ask Rebar to support the Elixir Mix.target(), but any thing that needs to be cross compiled is now broken.

I've drafted up one solution that i am incredibly unhappy with.

  1. add {:elixir_make, "~> 0.5", runtime: false} to the deps
  2. add a Makefile that basically recompiles the same assets that pc has already emitted:
# Set Erlang-specific compile and linker flags
ERL_CFLAGS ?= -I$(ERL_EI_INCLUDE_DIR)
ERL_LDFLAGS ?= -L$(ERL_EI_LIBDIR) -lei

CFLAGS += -fPIC --std=c11
LDFLAGS += -fPIC -shared

ifeq ($(ERL_EI_INCLUDE_DIR),)
$(warning ERL_EI_INCLUDE_DIR not set. Invoke via mix)
endif

ESQLITE_SRC = $(MIX_DEPS_PATH)/esqlite/c_src
ESQLITE_BUILD = $(MIX_BUILD_PATH)/lib/esqlite/obj
ESQLITE_PREFIX = $(MIX_BUILD_PATH)/lib/esqlite/priv

.PHONY: all clean

SQLITE_CFLAGS := -DSQLITE_THREADSAFE=1 \
-DSQLITE_USE_URI \
-DSQLITE_ENABLE_FTS3 \
-DSQLITE_ENABLE_FTS3_PARENTHESIS

all: $(ESQLITE_BUILD) \
		$(ESQLITE_PREFIX) \
		$(ESQLITE_PREFIX)/esqlite3_nif.so

clean:
	$(RM) $(ESQLITE_PREFIX)/*.so

## ESQLITE NIF HACK

$(ESQLITE_PREFIX)/esqlite3_nif.so: $(ESQLITE_BUILD)/sqlite3.o $(ESQLITE_BUILD)/queue.o $(ESQLITE_BUILD)/esqlite3_nif.o
	$(CC) -o $@ $(ERL_LDFLAGS) $(LDFLAGS) $^

$(ESQLITE_BUILD)/esqlite3_nif.o: $(ESQLITE_SRC)/esqlite3_nif.c
	$(CC) -c $(ERL_CFLAGS) $(CFLAGS) $(SQLITE_CFLAGS) -o $@ $<

$(ESQLITE_BUILD)/queue.o: $(ESQLITE_SRC)/queue.c
	$(CC) -c $(ERL_CFLAGS) $(CFLAGS) $(SQLITE_CFLAGS) -o $@ $<

$(ESQLITE_BUILD)/sqlite3.o: $(ESQLITE_SRC)/sqlite3.c
	$(CC) -c $(CFLAGS) $(SQLITE_CFLAGS) -o $@ $<

## DIRECTORIES

$(ESQLITE_BUILD):
	mkdir -p $(ESQLITE_BUILD)

$(ESQLITE_PREFIX):
	mkdir -p $(ESQLITE_PREFIX)

This has 1 positive side effect of allowing us to control the compiler options to sqlite independently of esqlite. This may or may not be a good thing.

There is another potential solution in #53 on esqlite

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions