Skip to content

Commit

Permalink
Add support for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed Nov 1, 2016
1 parent 0d95c81 commit aa53b39
Show file tree
Hide file tree
Showing 23 changed files with 1,443 additions and 142 deletions.
12 changes: 12 additions & 0 deletions .appveyor.yml
@@ -0,0 +1,12 @@
environment:
matrix:
- PYTHON: "C:\\Python27"
platform:
- x64
install:
- SET PATH=%PYTHON%;%PYTHON%/Scripts;%PATH%
- easy_install scons
build_script:
- build.bat
test_script:
- test.bat
181 changes: 122 additions & 59 deletions SConstruct
Expand Up @@ -3,67 +3,103 @@
import os
import platform

def BuildVM(cxx, arch, os, debug):
env = Environment()
env['CXX'] = cxx
def BuildVM(cxx, arch, target_os, debug):
if target_os == 'windows' and arch == 'ia32':
env = Environment(TARGET_ARCH='x86')
elif target_os == 'windows' and arch == 'x64':
env = Environment(TARGET_ARCH='x86_64')
else:
env = Environment()
env['CXX'] = cxx

outdir = 'out/'
configname = ''
if debug:
env['CCFLAGS'] += ['-DDEBUG']
outdir += 'Debug'
if target_os == 'windows':
env['CCFLAGS'] += ['/DDEBUG=1']
else:
env['CCFLAGS'] += ['-DDEBUG']
configname += 'Debug'
else:
env['CCFLAGS'] += ['-DNDEBUG']
outdir += 'Release'
if target_os == "windows":
env['CCFLAGS'] += ['/DNDEBUG']
else:
env['CCFLAGS'] += ['-DNDEBUG']
configname += 'Release'

if os == 'android':
outdir += 'Android'
if target_os == 'android':
configname += 'Android'

if arch == 'ia32':
env['CCFLAGS'] += ['-m32']
env['LINKFLAGS'] += ['-m32']
outdir += 'IA32/'
if target_os == 'windows':
env['LINKFLAGS'] += ['/MACHINE:X86']
else:
env['CCFLAGS'] += ['-m32']
env['LINKFLAGS'] += ['-m32']
configname += 'IA32'
elif arch == 'x64':
env['CCFLAGS'] += ['-m64']
env['LINKFLAGS'] += ['-m64']
outdir += 'X64/'
if target_os == 'windows':
env['LINKFLAGS'] += ['/MACHINE:X64']
else:
env['CCFLAGS'] += ['-m64']
env['LINKFLAGS'] += ['-m64']
configname += 'X64'
elif arch == 'arm':
outdir += 'ARM/'
configname += 'ARM'
elif arch == 'arm64':
outdir += 'ARM64/'
configname += 'ARM64'
elif arch == 'mips':
env['CCFLAGS'] += ['-EL']
env['LINKFLAGS'] += ['-EL']
outdir += 'MIPS/'
configname += 'MIPS'
elif arch == 'mips64':
env['CCFLAGS'] += ['-EL']
env['LINKFLAGS'] += ['-EL']
outdir += 'MIPS64/'
configname += 'MIPS64'
elif arch == 'riscv32':
env['CCFLAGS'] += ['-m32']
env['LINKFLAGS'] += ['-m32']
outdir += 'RISCV32/'
configname += 'RISCV32'
elif arch == 'riscv64':
env['CCFLAGS'] += ['-m64']
env['LINKFLAGS'] += ['-m64']
outdir += 'RISCV64/'

env['CCFLAGS'] += [
'-O3',
'-g3',
'-Werror',
'-Wall',
'-Wextra',
'-Wnon-virtual-dtor',
'-Wvla',
'-Wno-unused-parameter',
'-fno-rtti',
'-fno-exceptions',
'-fstack-protector',
'-fpic',
'-D_FORTIFY_SOURCE=2',
]
configname += 'RISCV64'

outdir = os.path.join('out', configname)

if target_os == "windows":
env['CCFLAGS'] += [
'/O2',
'/Z7', # Debug symbols
'/WX', # Warnings as errors
'/W3', # Most warnings
'/wd4200', # Zero-sized array in struct
'/wd4996', # Deprecated POSIX names
'/wd4244', # Implicit narrowing conversion
'/wd4800', # Implicit bool conversion
'/wd4146', # Negating unsigned type
'/D_HAS_EXCEPTIONS=0',
'/DSTRICT',
'/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1',
'/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1'
]
else:
env['CCFLAGS'] += [
'-O3',
'-g3',
'-Werror',
'-Wall',
'-Wextra',
'-Wnon-virtual-dtor',
'-Wvla',
'-Wno-unused-parameter',
'-fno-rtti',
'-fno-exceptions',
'-fstack-protector',
'-fpic',
'-D_FORTIFY_SOURCE=2',
]

if os == 'macos':
if target_os == 'macos':
env['LINKFLAGS'] += [
'-fPIE',
'-dead_strip',
Expand All @@ -73,7 +109,7 @@ def BuildVM(cxx, arch, os, debug):
'stdc++',
'pthread',
]
if os == 'linux':
elif target_os == 'linux':
env['LINKFLAGS'] += [
'-fPIE',
'-Wl,-z,relro,-z,now',
Expand All @@ -85,7 +121,7 @@ def BuildVM(cxx, arch, os, debug):
'stdc++',
'pthread',
]
elif os == 'android':
elif target_os == 'android':
env['LINKFLAGS'] += [
'-pie',
'-Wl,-z,relro,-z,now',
Expand All @@ -97,6 +133,12 @@ def BuildVM(cxx, arch, os, debug):
'stdc++',
'log',
]
elif target_os == 'windows':
env['LINKFLAGS'] += [
'/DYNAMICBASE', # Address space layout randomization
'/NXCOMPAT',
'/DEBUG', # Debug symbols
]

env['CPPPATH'] = ['src']

Expand All @@ -116,10 +158,12 @@ def BuildVM(cxx, arch, os, debug):
'os_android',
'os_linux',
'os_macos',
'os_win',
'os_thread',
'os_thread_android',
'os_thread_linux',
'os_thread_macos',
'os_thread_win',
'port',
'primitives',
'snapshot',
Expand All @@ -128,9 +172,11 @@ def BuildVM(cxx, arch, os, debug):
'virtual_memory_android',
'virtual_memory_linux',
'virtual_memory_macos',
'virtual_memory_win',
]
for cc in vm_ccs:
objects += env.Object(outdir + 'vm/' + cc + '.o', 'src/vm/' + cc + '.cc')
objects += env.Object(os.path.join(outdir, 'vm', cc + '.o'),
os.path.join('src', 'vm', cc + '.cc'))

double_conversion_ccs = [
'bignum',
Expand All @@ -143,30 +189,38 @@ def BuildVM(cxx, arch, os, debug):
'strtod',
]
for cc in double_conversion_ccs:
objects += env.Object(outdir + 'double-conversion/' + cc + '.o',
'src/double-conversion/' + cc + '.cc')
objects += env.Object(os.path.join(outdir, 'double-conversion', cc + '.o'),
os.path.join('src', 'double-conversion', cc + '.cc'))

program = env.Program(outdir + 'primordialsoup', objects)
program = env.Program(os.path.join(outdir, 'primordialsoup'), objects)
return str(program[0])


def BuildSnapshots(outdir, host_vm):
nssources = Glob('src/newspeak/*.ns')

nssources = Glob(os.path.join('src', 'newspeak', '*.ns'))
compilersnapshot = os.path.join('snapshots', 'compiler.vfuel')
snapshots = []
cmd = host_vm + ' snapshots/compiler.vfuel $SOURCES'
snapshots += [outdir + 'HelloApp.vfuel']
cmd += ' RuntimeForPrimordialSoup HelloApp ' + outdir + 'HelloApp.vfuel'
snapshots += [outdir + 'TestRunner.vfuel']
cmd += ' RuntimeWithBuildersForPrimordialSoup TestRunner ' + outdir + 'TestRunner.vfuel'
snapshots += [outdir + 'BenchmarkRunner.vfuel']
cmd += ' RuntimeForPrimordialSoup BenchmarkRunner ' + outdir + 'BenchmarkRunner.vfuel'
snapshots += [outdir + 'CompilerApp.vfuel']
cmd += ' RuntimeWithBuildersForPrimordialSoup CompilerApp ' + outdir + 'CompilerApp.vfuel'
cmd = host_vm + ' ' + compilersnapshot + ' $SOURCES'

helloout = os.path.join(outdir, 'HelloApp.vfuel')
snapshots += [helloout]
cmd += ' RuntimeForPrimordialSoup HelloApp ' + helloout

testout = os.path.join(outdir, 'TestRunner.vfuel')
snapshots += [testout]
cmd += ' RuntimeWithBuildersForPrimordialSoup TestRunner ' + testout

benchmarkout = os.path.join(outdir, 'BenchmarkRunner.vfuel')
snapshots += [benchmarkout]
cmd += ' RuntimeForPrimordialSoup BenchmarkRunner ' + benchmarkout

compilerout = os.path.join(outdir, 'CompilerApp.vfuel')
snapshots += [compilerout]
cmd += ' RuntimeWithBuildersForPrimordialSoup CompilerApp ' + compilerout

Command(target=snapshots, source=nssources, action=cmd)
Requires(snapshots, host_vm)
Depends(snapshots, 'snapshots/compiler.vfuel')
Depends(snapshots, compilersnapshot)


def Main():
Expand All @@ -176,18 +230,23 @@ def Main():
host_os = 'linux'
elif platform.system() == 'Darwin':
host_os = 'macos'
elif platform.system() == 'Windows':
host_os = 'windows'

target_cxx = ARGUMENTS.get('cxx_target', None);
host_cxx = None
if platform.system() == 'Linux':
host_cxx = 'g++'
elif platform.system() == 'Darwin':
host_cxx = 'clang++'
elif platform.system() == 'Windows':
host_cxx = 'cl'
host_cxx = ARGUMENTS.get('cxx_host', host_cxx)

target_arch = ARGUMENTS.get('arch', None)
host_arch = None
if platform.machine() == 'x86_64':
if (platform.machine() == 'x86_64' or
platform.machine() == 'AMD64'):
host_arch = 'x64'
elif platform.machine() == 'i386':
host_arch = 'ia32'
Expand All @@ -201,13 +260,17 @@ def Main():
host_arch = 'riscv32'
elif platform.machine() == 'riscv64':
host_arch = 'riscv64'
else:
print (platform.machine());
raise "Unknown machine"

# Always build for the host so we can create the snapshots.
BuildVM(host_cxx, host_arch, host_os, True)
host_vm = BuildVM(host_cxx, host_arch, host_os, False)
BuildSnapshots('out/snapshots/', host_vm)

if (target_os != None and host_os != target_os) or (target_arch != None and host_arch != target_arch):
if ((target_os != None and host_os != target_os) or
(target_arch != None and host_arch != target_arch)):
# If cross compiling, also build for the target.
BuildVM(target_cxx, target_arch, target_os, True)
BuildVM(target_cxx, target_arch, target_os, False)
Expand Down
1 change: 1 addition & 0 deletions build.bat
@@ -0,0 +1 @@
scons -Q --jobs %NUMBER_OF_PROCESSORS%
7 changes: 6 additions & 1 deletion src/vm/globals.h
Expand Up @@ -5,6 +5,10 @@
#ifndef VM_GLOBALS_H_
#define VM_GLOBALS_H_

#if defined(_WIN32)
#include <windows.h>
#endif // defined(_WIN32)

#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
Expand Down Expand Up @@ -206,7 +210,8 @@ template <class D, class S>
inline D bit_cast(const S& source) {
// Compile time assertion: sizeof(D) == sizeof(S). A compile error
// here means your D and S have different sizes.
PSOUP_UNUSED typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1];
PSOUP_UNUSED
typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1];

D destination;
// This use of memcpy is safe: source and destination cannot overlap.
Expand Down
1 change: 0 additions & 1 deletion src/vm/heap.h
Expand Up @@ -9,7 +9,6 @@
#include "vm/globals.h"
#include "vm/utils.h"
#include "vm/object.h"
#include "vm/message.h"
#include "vm/os.h"
#include "vm/random.h"
#include "vm/flags.h"
Expand Down
1 change: 1 addition & 0 deletions src/vm/isolate.cc
Expand Up @@ -7,6 +7,7 @@
#include "vm/heap.h"
#include "vm/interpreter.h"
#include "vm/lockers.h"
#include "vm/message.h"
#include "vm/os_thread.h"
#include "vm/snapshot.h"
#include "vm/thread_pool.h"
Expand Down
3 changes: 2 additions & 1 deletion src/vm/large_integer.cc
Expand Up @@ -1315,7 +1315,8 @@ double LargeInteger::AsDouble(LargeInteger* integer) {
// get kSignificandSize + 1 bits. If the last bit is 1 then we have to look
// at the remaining bits to know if we have to round up.
int needed_bits = kSignificandSize + 1;
// ASSERT((kBitsPerDigit < needed_bits) && (2 * kBitsPerDigit >= needed_bits));
// ASSERT((kBitsPerDigit < needed_bits) &&
// (2 * kBitsPerDigit >= needed_bits));
bool discarded_bits_were_zero = true;

const digit_t firstDigit = integer->digit(digit_index--);
Expand Down
15 changes: 0 additions & 15 deletions src/vm/main.cc
Expand Up @@ -30,21 +30,6 @@ class PrimordialSoup {
OS::Exit(-1);
}

if (false) {
OS::PrintErr("sizeof(Heap) %" Pd "\n", sizeof(Heap));
OS::PrintErr("sizeof(Isolate) %" Pd "\n", sizeof(Isolate));
OS::PrintErr("sizeof(Interpreter) %" Pd "\n", sizeof(Interpreter));
OS::PrintErr("sizeof(LookupCache) %" Pd "\n", sizeof(LookupCache));
OS::PrintErr("sizeof(ThreadPool) %" Pd "\n", sizeof(ThreadPool));
OS::PrintErr("sizeof(pthread_mutex_t) %" Pd "\n",
sizeof(pthread_mutex_t));
OS::PrintErr("sizeof(pthread_cond_t) %" Pd "\n", sizeof(pthread_cond_t));
OS::PrintErr("sizeof(jmp_buf) %" Pd "\n", sizeof(jmp_buf));
OS::PrintErr("sizeof(Monitor) %" Pd "\n", sizeof(Monitor));
OS::PrintErr("sizeof(OSThread) %" Pd "\n", sizeof(OSThread));
OS::PrintErr("sizeof(Thread) %" Pd "\n", sizeof(Thread));
}

OS::InitOnce();
OSThread::InitOnce();
Primitives::InitOnce();
Expand Down
2 changes: 0 additions & 2 deletions src/vm/message.h
Expand Up @@ -5,8 +5,6 @@
#ifndef VM_MESSAGE_H_
#define VM_MESSAGE_H_

#include <pthread.h>

#include "vm/os_thread.h"
#include "vm/lockers.h"
#include "vm/port.h"
Expand Down

0 comments on commit aa53b39

Please sign in to comment.