Skip to content

Commit

Permalink
Fuchsia: Initial check-in.
Browse files Browse the repository at this point in the history
Instructions to build and run are in README.fuchsia.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2117593002 .
  • Loading branch information
zanderso committed Jul 1, 2016
1 parent 4e2bcf1 commit a503570
Show file tree
Hide file tree
Showing 42 changed files with 1,608 additions and 20 deletions.
41 changes: 41 additions & 0 deletions README.fuchsia
@@ -0,0 +1,41 @@
This is a README file describing how to build Dart for Fuchsia. It assumes that
you have built the magenta kernel under //magenta, its toolchains are
under //toolchains, and that you have a Dart checkout under //dart. It is early
days and this is crufty. The process will improve from here.

1. First, set up some symlinks in your Dart checkout:

//dart/third_party/fuchsia_tools/toolchains
-> symlinked to //toolchains
//dart/third_party/fuchsia_tools/sysroot/x86_64/usr
-> symlinked to //magenta/build-magenta-qemu-x86-64/sysroot/

Also, copy the linker script:

//magenta$ cp kernel/arch/x86/64/user.ld build-magenta-qemu-x86-64/sysroot/

and similarly for arm64.

2. Build:

//dart$ tools/build.py -m product -a x64 --os=fuchsia fuchsia_test

This will produce //dart/out/ProductFuchsiaX64/fuchsia_test

3. Strip it:

//dart$ third_party/fuchsia_tools/toolchains/x86_64-elf-5.3.0-Linux-x86_64/bin/x86_64-elf-strip out/ProductFuchsiaX64/fuchsia_test -o out/ProductFuchsiaX64/fuchsia_test.stripped

4. Make a file //magenta/fuchsia_test.manifest containing:

bin/fuchsia_test=//dart/out/ProductFuchsiaX64/fuchsia_test.stripped

Where //dart is the actual path to your Dart checkout.

5. Make an extra bootfs:

//magenta$ build-magenta-qemu-x86-64/tools/mkbootfs -o fuchsia_test.bootfs fuchsia_test.manifest

6. Run:

//magenta$ ./scripts/run-magenta-x86-64 -x fuchsia_test.bootfs
7 changes: 7 additions & 0 deletions dart.gyp
Expand Up @@ -34,6 +34,13 @@
'runtime/dart-runtime.gyp:sample_extension',
],
},
{
'target_name': 'fuchsia_test',
'type': 'none',
'dependencies': [
'runtime/dart-runtime.gyp:fuchsia_test',
],
},
{
# This is the target that is built on the VM build bots. It
# must depend on anything that is required by the VM test
Expand Down
14 changes: 14 additions & 0 deletions runtime/bin/bin.gypi
Expand Up @@ -1057,6 +1057,20 @@
},
]
},
{
'target_name': 'fuchsia_test',
'type': 'executable',
'dependencies': [
'libdart_nosnapshot',
],
'include_dirs': [
'..',
'../include',
],
'sources': [
'fuchsia_test.cc',
],
},
{
# dart binary with a snapshot of corelibs built in.
'target_name': 'dart',
Expand Down
39 changes: 39 additions & 0 deletions runtime/bin/fuchsia_test.cc
@@ -0,0 +1,39 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include <stdio.h>
#include <stdlib.h>

#include <dart_api.h>

int main(void) {
fprintf(stderr, "Calling Dart_SetVMFlags\n");
fflush(stderr);
if (!Dart_SetVMFlags(0, NULL)) {
fprintf(stderr, "Failed to set flags\n");
fflush(stderr);
return -1;
}
fprintf(stderr, "Calling Dart_Initialize\n");
fflush(stderr);
char* error = Dart_Initialize(
NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
if (error != NULL) {
fprintf(stderr, "VM initialization failed: %s\n", error);
fflush(stderr);
free(error);
return -1;
}
fprintf(stderr, "Success!\n");
fflush(stderr);
return 0;
}
9 changes: 6 additions & 3 deletions runtime/lib/timeline.cc
Expand Up @@ -54,6 +54,7 @@ DEFINE_NATIVE_ENTRY(Timeline_getThreadCpuClock, 0) {


DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) {
#ifndef PRODUCT
if (!FLAG_support_timeline) {
return Object::null();
}
Expand Down Expand Up @@ -114,12 +115,13 @@ DEFINE_NATIVE_ENTRY(Timeline_reportTaskEvent, 6) {

// json was allocated in the zone and a copy will be stored in event.
event->CompleteWithPreSerializedJSON(json);

#endif
return Object::null();
}


DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) {
#ifndef PRODUCT
if (!FLAG_support_timeline) {
return Object::null();
}
Expand Down Expand Up @@ -185,12 +187,13 @@ DEFINE_NATIVE_ENTRY(Timeline_reportCompleteEvent, 5) {
end_cpu);
// json was allocated in the zone and a copy will be stored in event.
event->CompleteWithPreSerializedJSON(json);

#endif
return Object::null();
}


DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) {
#ifndef PRODUCT
if (!FLAG_support_timeline) {
return Object::null();
}
Expand Down Expand Up @@ -228,7 +231,7 @@ DEFINE_NATIVE_ENTRY(Timeline_reportInstantEvent, 4) {
event->Instant("", start.AsInt64Value());
// json was allocated in the zone and a copy will be stored in event.
event->CompleteWithPreSerializedJSON(json);

#endif
return Object::null();
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/platform/globals.h
Expand Up @@ -113,7 +113,7 @@
// Windows, both 32- and 64-bit, regardless of the check for _WIN32.
#define TARGET_OS_WINDOWS 1

#else
#elif !defined(TARGET_OS_FUCHSIA)
#error Automatic target os detection failed.
#endif

Expand Down
5 changes: 5 additions & 0 deletions runtime/platform/math.h
Expand Up @@ -8,11 +8,16 @@
// We must take these math functions from the C++ header file as long as we
// are using the STL. Otherwise the Android build will break due to confusion
// between C++ and C headers when math.h is also included.
#if !defined(TARGET_OS_FUCHSIA)
#include <cmath>

#define isinf(val) std::isinf(val)
#define isnan(val) std::isnan(val)
#define signbit(val) std::signbit(val)
#define isfinite(val) std::isfinite(val)
#else
// TODO(zra): When Fuchsia has STL, do the same thing as above.
#include <math.h>
#endif

#endif // PLATFORM_MATH_H_
2 changes: 2 additions & 0 deletions runtime/platform/utils.h
Expand Up @@ -215,6 +215,8 @@ class Utils {

#if defined(TARGET_OS_ANDROID)
#include "platform/utils_android.h"
#elif defined(TARGET_OS_FUCHSIA)
#include "platform/utils_fuchsia.h"
#elif defined(TARGET_OS_LINUX)
#include "platform/utils_linux.h"
#elif defined(TARGET_OS_MACOS)
Expand Down
67 changes: 67 additions & 0 deletions runtime/platform/utils_fuchsia.h
@@ -0,0 +1,67 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#ifndef PLATFORM_UTILS_FUCHSIA_H_
#define PLATFORM_UTILS_FUCHSIA_H_

#include "platform/assert.h"

namespace dart {

inline int Utils::CountLeadingZeros(uword x) {
UNIMPLEMENTED();
return 0;
}


inline int Utils::CountTrailingZeros(uword x) {
UNIMPLEMENTED();
return 0;
}


inline uint16_t Utils::HostToBigEndian16(uint16_t value) {
UNIMPLEMENTED();
return 0;
}


inline uint32_t Utils::HostToBigEndian32(uint32_t value) {
UNIMPLEMENTED();
return 0;
}


inline uint64_t Utils::HostToBigEndian64(uint64_t value) {
UNIMPLEMENTED();
return 0;
}


inline uint16_t Utils::HostToLittleEndian16(uint16_t value) {
UNIMPLEMENTED();
return 0;
}


inline uint32_t Utils::HostToLittleEndian32(uint32_t value) {
UNIMPLEMENTED();
return 0;
}


inline uint64_t Utils::HostToLittleEndian64(uint64_t value) {
UNIMPLEMENTED();
return 0;
}


inline char* Utils::StrError(int err, char* buffer, size_t bufsize) {
UNIMPLEMENTED();
return NULL;
}

} // namespace dart

#endif // PLATFORM_UTILS_FUCHSIA_H_
2 changes: 2 additions & 0 deletions runtime/vm/atomic.h
Expand Up @@ -77,6 +77,8 @@ class AtomicOperations : public AllStatic {

#if defined(TARGET_OS_ANDROID)
#include "vm/atomic_android.h"
#elif defined(TARGET_OS_FUCHSIA)
#include "vm/atomic_fuchsia.h"
#elif defined(TARGET_OS_LINUX)
#include "vm/atomic_linux.h"
#elif defined(TARGET_OS_MACOS)
Expand Down
66 changes: 66 additions & 0 deletions runtime/vm/atomic_fuchsia.h
@@ -0,0 +1,66 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#ifndef VM_ATOMIC_FUCHSIA_H_
#define VM_ATOMIC_FUCHSIA_H_

#if !defined VM_ATOMIC_H_
#error Do not include atomic_fuchsia.h directly. Use atomic.h instead.
#endif

#if !defined(TARGET_OS_FUCHSIA)
#error This file should only be included on Fuchsia builds.
#endif

#include "platform/assert.h"

namespace dart {

inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) {
UNIMPLEMENTED();
return 0;
}


inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) {
UNIMPLEMENTED();
}


inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) {
UNIMPLEMENTED();
}


inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) {
UNIMPLEMENTED();
return 0;
}


inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) {
UNIMPLEMENTED();
}


#if !defined(USING_SIMULATOR_ATOMICS)
inline uword AtomicOperations::CompareAndSwapWord(uword* ptr,
uword old_value,
uword new_value) {
UNIMPLEMENTED();
return 0;
}


inline uint32_t AtomicOperations::CompareAndSwapUint32(uint32_t* ptr,
uint32_t old_value,
uint32_t new_value) {
UNIMPLEMENTED();
return 0;
}
#endif // !defined(USING_SIMULATOR_ATOMICS)

} // namespace dart

#endif // VM_ATOMIC_FUCHSIA_H_

0 comments on commit a503570

Please sign in to comment.