Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix embedding example, simplify Makefile, and test it #20535

Closed
wants to merge 7 commits into from

Conversation

ihnorton
Copy link
Member

@ihnorton ihnorton commented Feb 9, 2017

  • get rid of makefile cruft
  • build in-place instead of putting in usr/bin
  • use julia-config for flags, as documented in manual

(related: #18421)

@ihnorton ihnorton added the embedding Embedding Julia using the C API label Feb 9, 2017
@@ -1,41 +1,25 @@
JULIAHOME = $(abspath ..)
include $(JULIAHOME)/Make.inc
JULIA = $(abspath ../usr/bin/julia)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't right for an out-of-tree build

JULIAHOME = $(abspath ..)
include $(JULIAHOME)/Make.inc
JULIA = $(abspath ../usr/bin/julia)
JL_SHARE = $(shell $(JULIA) -e 'print(joinpath(JULIA_HOME,Base.DATAROOTDIR,"julia"))')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may require spawn

ifneq ($(UNTRUSTED_SYSTEM_LIBM),0)
JLDFLAGS += $(WHOLE_ARCHIVE) $(build_libdir)/libopenlibm.a $(NO_WHOLE_ARCHIVE)
endif
ifeq ($(OS),Windows_NT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not correct for cross-compiling

src/julia.h Outdated
@@ -1313,6 +1313,7 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel);
JL_DLLEXPORT void jl_init(const char *julia_home_dir);
JL_DLLEXPORT void jl_init_with_image(const char *julia_home_dir,
const char *image_relative_path);
JL_DLLEXPORT const char* jl_get_default_sysimg_path();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if exported, needs JL_DLLEXPORT on both prototype and implementation

@ihnorton
Copy link
Member Author

Updated, thanks. I'm going for non-reliance on Make.inc, so that this can serve as a usable template. However, added checks for spawn and BUILDROOT independently (to handle cross-compile and out-of-tree). Hopefully sufficient, though I'm not set up to test those right now.

I'll note that this example isn't built at all right now with out-of-tree.

@ihnorton
Copy link
Member Author

Win64 and OSX test failures seem unrelated.


ifeq ($(USE_SYSTEM_LIBM),0)
ifneq ($(UNTRUSTED_SYSTEM_LIBM),0)
JLDFLAGS += $(WHOLE_ARCHIVE) $(build_libdir)/libopenlibm.a $(NO_WHOLE_ARCHIVE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does julia-config handle this and the llvm-config output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libm yes, llvm-config no. Doesn't libjulia link llvm already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but presumably the llvm-config --ldflags call was needed for something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was added in 072a861 when the file was created. My guess is copy-paste or prior/local build issue. If it breaks the example we can put it back.

test/examples.jl Outdated

# test that the embedding example runs without error
let
lines = readlines(pipeline(`$(joinpath(JULIA_HOME,Base.DATAROOTDIR,"doc","julia","examples","embedding","embedding"))`, stderr=DevNull))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap long line

$(CC) $^ -o $@ $(CFLAGS) $(DEBUGFLAGS)

clean:
rm -f *.o *.do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like this will create any object files any more

@tkelman
Copy link
Contributor

tkelman commented Feb 13, 2017

we shouldn't install binaries in the same place as documentation and source code. installing and redistributing the compiled embedding results isn't the most useful test of this, see my comments on #18688

@ihnorton
Copy link
Member Author

installing and redistributing the compiled embedding results isn't the most useful test of this, see my comments on #18688

Ok:

  • I put the binary in libexec in the latest update, because I agree with Yichao (and your thumbs-up) in that thread that this could be a useful test of relocatability, which I will have a follow-up PR to make possible.
  • I made the test optional, as you requested in that thread, and added to appveyor/travis scripts.

@ihnorton ihnorton changed the title Fix embedding example and simplify Makefile Fix embedding example, simplify Makefile, and test it Feb 13, 2017
# hooks for julia build system
ifdef BUILDROOT
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))/
BINDIR := $(abspath $(BUILDROOT)/usr/libexec)/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build_libexecdir

@ihnorton ihnorton force-pushed the fix_embedding branch 2 times, most recently from dcfd49a to 69ea5ea Compare February 16, 2017 18:14
$(error "Please set JULIA to the path of the target julia binary!")
endif
ifndef BIN
$(error "Please set BIN to the path of the build directory!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could maybe use a bit more clarification what is meant by this

$(BIN)/embedding$(EXE): embedding.c
$(CC) $^ -o $@ $(CFLAGS)

$(BINDIR)/embedding-debug$(EXE): embedding.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be BIN ?

debug: $(BIN)/embedding-debug$(EXE)

$(BIN)/embedding$(EXE): embedding.c
$(CC) $^ -o $@ $(CFLAGS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to also explicitly error if CC isn't set, or default to cc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make already does that

@@ -70,9 +70,9 @@ function cflags()
arg2 = replace(includeDir(),"\\","\\\\")
threading_def = threadingOn() ? "-DJULIA_ENABLE_THREADING=1 " : ""
if is_unix()
return """$(threading_def)-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
return """-std=gnu99 $(threading_def)-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the runtime need this, or the code in the embedding example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the runtime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we using gnu extensions in our headers, or which compiler versions don't default to c99 mode?

@@ -14,7 +14,7 @@ double my_c_sqrt(double x)

int main()
{
jl_init(NULL);
jl_init(JULIA_INIT_DIR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still work with NULL as the argument?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, even better, it looks like jl_init takes no arguments now?

julia_init(JL_IMAGE_JULIA_HOME);
jl_exception_clear();
}

JL_DLLEXPORT void jl_init(const char *julia_home_dir)
JL_DLLEXPORT void jl_init()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be jl_init(void).

JL_DLLEXPORT int jl_is_initialized(void);
JL_DLLEXPORT void jl_atexit_hook(int status);
JL_DLLEXPORT void JL_NORETURN jl_exit(int status);
JL_DLLEXPORT const char* jl_pathname_for_handle(void *handle);
JL_DLLEXPORT const char* jl_get_default_sysimg_path();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated and needs (void).

@JeffBezanson
Copy link
Member

Bump.

@JeffBezanson
Copy link
Member

Moved to #21299.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedding Embedding Julia using the C API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants