Skip to content

Commit

Permalink
Merge pull request JuliaLang#7761 from tkelman/msvc-again
Browse files Browse the repository at this point in the history
RFC: MSVC continued
  • Loading branch information
tkelman committed Oct 6, 2014
2 parents 592ec62 + 9b687fa commit b5a0f5f
Show file tree
Hide file tree
Showing 32 changed files with 527 additions and 60 deletions.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ their own licenses:
- [FFTW](http://fftw.org/doc/License-and-Copyright.html)
- [GMP](http://gmplib.org/manual/Copying.html#Copying)
- [MPFR](http://www.mpfr.org/mpfr-current/mpfr.html#Copying)
- [MUSL](http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT)
- [OPENBLAS](https://raw.github.com/xianyi/OpenBLAS/master/LICENSE)
- [LAPACK](http://netlib.org/lapack/LICENSE.txt)
- [PCRE](http://www.pcre.org/licence.txt)
Expand Down
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ JLDFLAGS += -Wl,--large-address-aware
endif
else
OSLIBS += kernel32.lib ws2_32.lib psapi.lib advapi32.lib iphlpapi.lib shell32.lib winmm.lib
JLDFLAGS =
JLDFLAGS = -stack:8388608
endif
JCPPFLAGS += -D_WIN32_WINNT=0x0600
UNTRUSTED_SYSTEM_LIBM = 1
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ $(build_private_libdir)/sys%ji: $(build_private_libdir)/sys%o
.SECONDARY: $(build_private_libdir)/sys0.o

$(build_private_libdir)/sys%$(SHLIB_EXT): $(build_private_libdir)/sys%o
ifneq ($(USEMSVC), 1)
$(CXX) -shared -fPIC -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -o $@ $< \
$$([ $(OS) = Darwin ] && echo '' -Wl,-undefined,dynamic_lookup || echo '' -Wl,--unresolved-symbols,ignore-all ) \
$$([ $(OS) = WINNT ] && echo '' -ljulia -lssp)
$(DSYMUTIL) $@
else
@true
endif

$(build_private_libdir)/sys0.o:
@$(QUIET_JULIA) cd base && \
Expand Down
2 changes: 1 addition & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function frexp(x::Float64)
k = int(xu >> 52) & 0x07ff
if k == 0 # x is subnormal
x == zero(x) && return x,0
x *= 0x1p54 # normalise significand
x *= 1.8014398509481984e16 # 0x1p54, normalise significand
xu = reinterpret(Uint64,x)
k = int(xu >> 52) & 0x07ff - 54
elseif k == 0x07ff # NaN or Inf
Expand Down
16 changes: 8 additions & 8 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function cos_kernel(x::DoubleFloat64)
end

function sin_kernel(x::DoubleFloat32)
S1 = -0x15555554cbac77.0p-55
S2 = 0x111110896efbb2.0p-59
S3 = -0x1a00f9e2cae774.0p-65
S4 = 0x16cd878c3b46a7.0p-71
S1 = -0.16666666641626524
S2 = 0.008333329385889463
S3 = -0.00019839334836096632
S4 = 2.718311493989822e-6

z = x.hi*x.hi
w = z*z
Expand All @@ -62,10 +62,10 @@ function sin_kernel(x::DoubleFloat32)
end

function cos_kernel(x::DoubleFloat32)
C0 = -0x1ffffffd0c5e81.0p-54
C1 = 0x155553e1053a42.0p-57
C2 = -0x16c087e80f1e27.0p-62
C3 = 0x199342e0ee5069.0p-68
C0 = -0.499999997251031
C1 = 0.04166662332373906
C2 = -0.001388676377460993
C3 = 2.439044879627741e-5

z = x.hi*x.hi
w = z*z
Expand Down
191 changes: 191 additions & 0 deletions contrib/windows/msys_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/bin/sh
# Script to compile Julia in MSYS assuming 7zip is installed and on the path,
# or Cygwin assuming make, curl, and mingw64-$ARCH-gcc-g++ are installed

# Run in top-level Julia directory
cd `dirname "$0"`/../..
# Stop on error
set -e

# If ARCH environment variable not set, choose based on uname -m
if [ -z "$ARCH" ]; then
export ARCH=`uname -m`
fi
if [ $ARCH = x86_64 ]; then
bits=64
archsuffix=64
else
bits=32
archsuffix=86
fi
echo "" > Make.user

# Set XC_HOST if in Cygwin
if [ -n "`uname | grep CYGWIN`" ]; then
if [ -z "$XC_HOST" ]; then
export XC_HOST="$ARCH-w64-mingw32"
fi
echo "override BUILD_MACHINE = $ARCH-pc-cygwin" >> Make.user
CROSS_COMPILE="$XC_HOST-"
# Set HOSTCC if we don't have Cygwin gcc installed
if [ -z "`which gcc 2>/dev/null`" ]; then
echo 'override HOSTCC = $(CROSS_COMPILE)gcc' >> Make.user
fi
else
CROSS_COMPILE=""
fi

# Download most recent Julia binary for dependencies
echo "" > get-deps.log
if ! [ -e julia-installer.exe ]; then
f=julia-nightly-win$bits.exe
echo "Downloading $f"
curl -kLsSo $f http://status.julialang.org/download/win$bits
echo "Extracting $f"
7z x -y $f >> get-deps.log
fi
for i in bin/*.dll Git/bin/msys-1.0.dll Git/bin/msys-perl5_8.dll Git/bin/*.exe; do
if [ -z "$(file `which 7z` 2>/dev/null | grep shell)" ]; then
# Windows version of 7z.exe, use backslashes
7z e -y julia-installer.exe "\$_OUTDIR/$i" \
-ousr\\`dirname $i | sed -e 's|/julia||' -e 's|/|\\\\|g'` >> get-deps.log
else
# p7zip, use forward slashes
7z e -y julia-installer.exe "\$_OUTDIR/$i" \
-ousr/`dirname $i | sed -e 's|/julia||'` >> get-deps.log
fi
done
# Remove libjulia.dll if it was copied from downloaded binary
rm -f usr/bin/libjulia.dll
rm -f usr/bin/libjulia-debug.dll

mingw=http://sourceforge.net/projects/mingw
if [ -z "$USEMSVC" ]; then
if [ -z "`which ${CROSS_COMPILE}gcc 2>/dev/null`" ]; then
f=mingw-w$bits-bin-$ARCH-20140102.7z
if ! [ -e $f ]; then
echo "Downloading $f"
curl -kLOsS $mingw-w64-dgn/files/mingw-w64/$f
fi
echo "Extracting $f"
7z x -y $f >> get-deps.log
export PATH=$PATH:$PWD/mingw$bits/bin
# If there is a version of make.exe here, it is mingw32-make which won't work
rm -f mingw$bits/bin/make.exe
fi
export AR=${CROSS_COMPILE}ar

f=llvm-3.3-$ARCH-w64-mingw32-juliadeps.7z
# The MinGW binary version of LLVM doesn't include libgtest or libgtest_main
mkdir -p usr/lib
$AR cr usr/lib/libgtest.a
$AR cr usr/lib/libgtest_main.a
else
echo "override USEMSVC = 1" >> Make.user
echo "override ARCH = $ARCH" >> Make.user
if [ $ARCH = x86_64 ]; then
echo "override MARCH = x86-64" >> Make.user
else
echo "override MARCH = $ARCH" >> Make.user
fi
echo "override XC_HOST = " >> Make.user
export CC="$PWD/deps/libuv/compile cl -nologo -MD -Z7"
export AR="$PWD/deps/libuv/ar-lib lib"
export LD="$PWD/linkld link"
echo "override CC = $CC" >> Make.user
echo 'override CXX = $(CC) -EHsc' >> Make.user
echo "override AR = $AR" >> Make.user
echo "override LD = $LD -DEBUG" >> Make.user

for i in share/julia/base/pcre_h.jl; do
7z e -y julia-installer.exe "\$_OUTDIR/$i" -obase >> get-deps.log
done

f=llvm-3.3-$ARCH-msvc12-juliadeps.7z
fi

if ! [ -e $f ]; then
echo "Downloading $f"
curl -kLOsS http://sourceforge.net/projects/juliadeps-win/files/$f
fi
echo "Extracting $f"
7z x -y $f >> get-deps.log
echo 'LLVM_CONFIG = $(JULIAHOME)/usr/bin/llvm-config' >> Make.user

if [ -z "`which make 2>/dev/null`" ]; then
if [ -n "`uname | grep CYGWIN`" ]; then
echo "Install the Cygwin package for 'make' and try again."
exit 1
fi
f="/make/make-3.81-2/make-3.81-2-msys-1.0.11-bin.tar"
if ! [ -e `basename $f.lzma` ]; then
echo "Downloading `basename $f`"
curl -kLOsS $mingw/files/MSYS/Base$f.lzma
fi
7z x -y `basename $f.lzma` >> get-deps.log
tar -xf `basename $f`
# msysgit has an ancient version of touch that fails with `touch -c nonexistent`
cp usr/Git/bin/echo.exe bin/touch.exe
export PATH=$PWD/bin:$PATH
fi

f=mingw$bits-pcre-8.34-2.fc21.noarch
if ! [ -e $f.rpm ]; then
echo "Downloading $f"
curl -kLOsS http://rpmfind.net/linux/fedora/linux/development/rawhide/x86_64/os/Packages/m/$f.rpm
fi
7z x -y $f.rpm >> get-deps.log
7z x -y $f.cpio >> get-deps.log
echo 'override PCRE_CONFIG = $(JULIAHOME)/usr/bin/pcre-config' >> Make.user
# Move downloaded bin, lib, and include files into build tree
mv usr/$ARCH-w64-mingw32/sys-root/mingw/bin/* usr/bin
mv usr/$ARCH-w64-mingw32/sys-root/mingw/lib/*.dll.a usr/lib
mv usr/$ARCH-w64-mingw32/sys-root/mingw/include/* usr/include
# Modify prefix in pcre-config
sed -i "s|prefix=/usr/$ARCH-w64-mingw32/sys-root/mingw|prefix=$PWD/usr|" usr/bin/pcre-config
chmod +x usr/bin/*

for lib in LLVM SUITESPARSE ARPACK BLAS LAPACK FFTW \
GMP MPFR PCRE LIBUNWIND RMATH OPENSPECFUN; do
echo "USE_SYSTEM_$lib = 1" >> Make.user
done
echo 'LIBBLAS = -L$(JULIAHOME)/usr/bin -lopenblas' >> Make.user
echo 'LIBBLASNAME = libopenblas' >> Make.user
echo 'override LIBLAPACK = $(LIBBLAS)' >> Make.user
echo 'override LIBLAPACKNAME = $(LIBBLASNAME)' >> Make.user

# Remaining dependencies:
# openlibm since we need it as a static library to work properly
# mojibake since its headers are not in the binary download
echo 'override STAGE1_DEPS = uv' >> Make.user
echo 'override STAGE2_DEPS = mojibake' >> Make.user
echo 'override STAGE3_DEPS = ' >> Make.user
make -C deps get-openlibm get-mojibake

# Disable git and enable verbose make in AppVeyor
if [ -n "$APPVEYOR" ]; then
echo 'override NO_GIT = 1' >> Make.user
echo 'VERBOSE = 1' >> Make.user
fi

if [ -n "$USEMSVC" ]; then
# Create a modified version of compile for wrapping link
sed -e 's/-link//' -e 's/cl/link/g' -e 's/ -Fe/ -OUT:/' \
-e 's|$dir/$lib|$dir/lib$lib|g' deps/libuv/compile > linkld
chmod +x linkld

# Openlibm doesn't build well with MSVC right now
echo 'USE_SYSTEM_OPENLIBM = 1' >> Make.user
# Since we don't have a static library for openlibm
echo 'override UNTRUSTED_SYSTEM_LIBM = 0' >> Make.user

# Compile libuv and mojibake without -TP first, then add -TP
make -C deps install-uv install-mojibake
cp usr/lib/uv.lib usr/lib/libuv.a
echo 'override CC += -TP' >> Make.user
else
echo 'override STAGE1_DEPS += openlibm' >> Make.user
fi

make
#make debug
16 changes: 11 additions & 5 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ install-llvm: $(LLVM_OBJ_TARGET)

UV_SRC_TARGET = libuv/.libs/libuv.a
UV_OBJ_TARGET = $(build_libdir)/libuv.a

UV_CFLAGS =
ifeq ($(USEMSVC), 1)
UV_CFLAGS += -DBUILDING_UV_SHARED
Expand All @@ -526,9 +527,14 @@ ifeq ($(USEICC), 1)
UV_CFLAGS += -static-intel
endif

UV_OPTS += LDFLAGS="$(LDFLAGS) $(CLDFLAGS) -v"
UV_MFLAGS += LDFLAGS="$(LDFLAGS) $(CLDFLAGS) -v"
ifneq ($(UV_CFLAGS),)
UV_OPTS += CFLAGS="$(UV_CFLAGS)"
UV_MFLAGS += CFLAGS="$(UV_CFLAGS)"
endif
ifneq ($(USEMSVC), 1)
UV_FLAGS = $(UV_MFLAGS)
else
UV_FLAGS = --disable-shared $(UV_MFLAGS)
endif

libuv/configure:
Expand All @@ -541,14 +547,14 @@ libuv/config.status: $(JULIAHOME)/.git/modules/deps/libuv/HEAD
endif
libuv/config.status: libuv/configure
cd libuv && \
./configure --with-pic $(CONFIGURE_COMMON) $(UV_OPTS)
./configure --with-pic $(CONFIGURE_COMMON) $(UV_FLAGS)
touch -c $@
$(UV_SRC_TARGET): libuv/config.status
touch -c libuv/aclocal.m4
touch -c libuv/Makefile.in
touch -c libuv/configure
touch -c libuv/config.status
$(MAKE) -C libuv $(UV_OPTS)
$(MAKE) -C libuv $(UV_MFLAGS)
touch -c $@
libuv/checked: $(UV_SRC_TARGET)
ifeq ($(OS),$(BUILD_OS))
Expand Down Expand Up @@ -1249,7 +1255,7 @@ ifeq (exists, $(shell [ -d $(JULIAHOME)/.git/modules/deps/libmojibake ] && echo
$(MOJIBAKE_SRC_TARGET): $(JULIAHOME)/.git/modules/deps/libmojibake/HEAD
endif
$(MOJIBAKE_SRC_TARGET): libmojibake/Makefile
$(MAKE) -C libmojibake cc="$(CC) -O2 -std=c99 $(fPIC)" AR="$(AR)" libmojibake.a
$(MAKE) -C libmojibake cc="$(CC) -O2 -std=c99 $(fPIC) -DMOJIBAKE_EXPORTS" AR="$(AR)" libmojibake.a
touch -c $@
libmojibake/checked: $(MOJIBAKE_SRC_TARGET)
ifeq ($(OS),$(BUILD_OS))
Expand Down
2 changes: 1 addition & 1 deletion deps/libmojibake
Submodule libmojibake updated from bc357b to df71da
14 changes: 7 additions & 7 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DEBUG_LIBS = $(WHOLE_ARCHIVE) $(JULIAHOME)/src/flisp/libflisp-debug.a $(WHOLE_AR
RELEASE_LIBS = $(WHOLE_ARCHIVE) $(JULIAHOME)/src/flisp/libflisp.a $(WHOLE_ARCHIVE) $(JULIAHOME)/src/support/libsupport.a $(COMMON_LIBS)

OBJS = $(SRCS:%=%.o)
DOBJS = $(SRCS:%=%.do)
DOBJS = $(SRCS:%=%.dbg.obj)
DEBUGFLAGS += $(FLAGS)
SHIPFLAGS += $(FLAGS)

Expand All @@ -50,14 +50,14 @@ HEADERS = julia.h julia_internal.h options.h $(wildcard support/*.h) $(LIBUV_INC

%.o: %.c $(HEADERS)
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(SHIPFLAGS) -DNDEBUG -c $< -o $@)
%.do: %.c $(HEADERS)
%.dbg.obj: %.c $(HEADERS)
@$(call PRINT_CC, $(CC) $(CPPFLAGS) $(CFLAGS) $(DEBUGFLAGS) -c $< -o $@)
%.o: %.cpp $(HEADERS)
@$(call PRINT_CC, $(CXX) $(call exec,$(LLVM_CONFIG) --cxxflags) $(CPPFLAGS) $(CXXFLAGS) $(SHIPFLAGS) -c $< -o $@)
%.do: %.cpp $(HEADERS)
%.dbg.obj: %.cpp $(HEADERS)
@$(call PRINT_CC, $(CXX) $(call exec,$(LLVM_CONFIG) --cxxflags) $(CPPFLAGS) $(CXXFLAGS) $(DEBUGFLAGS) -c $< -o $@)

ast.o ast.do: julia_flisp.boot.inc flisp/*.h
ast.o ast.dbg.obj: julia_flisp.boot.inc flisp/*.h

julia_flisp.boot.inc: julia_flisp.boot flisp/libflisp.a
@$(call PRINT_FLISP, $(call spawn,./flisp/flisp) ./bin2hex.scm < $< > $@)
Expand All @@ -66,8 +66,8 @@ julia_flisp.boot: julia-parser.scm julia-syntax.scm \
match.scm utils.scm jlfrontend.scm mk_julia_flisp_boot.scm flisp/libflisp.a
@$(call PRINT_FLISP, $(call spawn,./flisp/flisp) ./mk_julia_flisp_boot.scm)

codegen.o codegen.do: intrinsics.cpp debuginfo.cpp cgutils.cpp ccall.cpp disasm.cpp
builtins.o builtins.do: table.c
codegen.o codegen.dbg.obj: intrinsics.cpp debuginfo.cpp cgutils.cpp ccall.cpp disasm.cpp
builtins.o builtins.dbg.obj: table.c

support/libsupport.a: support/*.h support/*.c
$(MAKE) -C support
Expand Down Expand Up @@ -114,7 +114,7 @@ libjulia-release: $(build_shlibdir)/libjulia.$(SHLIB_EXT)
clean:
-rm -f $(build_shlibdir)/libjulia*
-rm -f julia_flisp.boot julia_flisp.boot.inc
-rm -f *.do *.o *~ *# *.$(SHLIB_EXT) *.a
-rm -f *.dbg.obj *.o *~ *# *.$(SHLIB_EXT) *.a

clean-flisp:
-$(MAKE) -C flisp clean
Expand Down
2 changes: 1 addition & 1 deletion src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ static jl_sym_t *mk_symbol(const char *str)
sym = (jl_sym_t*)malloc(nb);
#else
if (sym_pool == NULL || pool_ptr+nb > sym_pool+SYM_POOL_SIZE) {
sym_pool = malloc(SYM_POOL_SIZE);
sym_pool = (char*)malloc(SYM_POOL_SIZE);
pool_ptr = sym_pool;
}
sym = (jl_sym_t*)pool_ptr;
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ DLLEXPORT int jl_substrtod(char *str, size_t offset, int len, double *out)
int err = 0;
if (!(*pend == '\0' || isspace((unsigned char)*pend) || *pend == ',')) {
// confusing data outside substring. must copy.
char *newstr = malloc(len+1);
char *newstr = (char*)malloc(len+1);
memcpy(newstr, bstr, len);
newstr[len] = 0;
bstr = newstr;
Expand Down Expand Up @@ -700,7 +700,7 @@ DLLEXPORT int jl_substrtof(char *str, int offset, int len, float *out)
int err = 0;
if (!(*pend == '\0' || isspace((unsigned char)*pend) || *pend == ',')) {
// confusing data outside substring. must copy.
char *newstr = malloc(len+1);
char *newstr = (char*)malloc(len+1);
memcpy(newstr, bstr, len);
newstr[len] = 0;
bstr = newstr;
Expand Down
2 changes: 1 addition & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static Value *emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
jl_value_t *rtt = rt;

size_t nargt = jl_tuple_len(tt);
Value *argvals[nargt];
Value **argvals = (Value**) alloca(nargt*sizeof(Value*));
std::vector<llvm::Type*> argtypes;
/*
* Semantics for arguments are as follows:
Expand Down
Loading

0 comments on commit b5a0f5f

Please sign in to comment.