Difference between revisions of "Mono-D"

From D Wiki
Jump to: navigation, search
(Setup Mono-D: Fixed the include path for OS X)
Line 168: Line 168:

Revision as of 16:46, 13 March 2018

Mono-D brings D support to the cross-platform XamarinStudio/MonoDevelop IDE.

Mono-D screenshot1.png


  • D Project management
    • Managing files & resources
    • Managing inter-project dependencies in a solution
    • Build projects and prepare them for being deployed
  • Ad hoc DUB support. Despite the package.json/dub.json file not being a native format that is supported by the Mono/.Net facilities, there's still a bunch of things wrapped for being used within MD.
    • Open DUB package.json/dub.json files as projects
    • Resolving package dependencies and subpackages and opening all of them as projects, too
    • Build support
    • ...
  • Basic Visual-D project format support
  • dmd, gdc, ldc2, rdmd, dub, make toolchain support
  • Rich editing & refactoring facilities:
    • Halfway™ decent auto code completion including pre-compile time
      • template deduction & evaluation,
      • mixins & mixin expression,
      • expression value as well as
      • compiler traits,
      • op overload evaluation & deduction that is used to provide extremely more accurate information about which symbols could be accessed or typed in a particular code context
    • Obligatory things like definition lookup,
    • Code symbol reference highlighting,
    • Semantic type identifer highlighting,
    • Optional diff-based syntax highlighting (Can be toggled via pressing Ctrl+Alt+K or in the global D options),
    • Diet template file highlighting.
    • Mixin expression pre-compilation to see what a mixin will look like when being compiled
    • Automatically generating method stubs for overridable methods
      Mono-d method override.png
    • Code declaration foldings
    • User-generated foldings via
//region My Region
int myCodes;
    • Obligatory AST outlining for easy access of stuff declared in a D source file
    • Intelligent code indentation
    • Basic code formatting support which reorganizes all kinds of code elements, not only line beginnings
    • Invoking a project's unit tests via pressing Ctrl+T
    • ...

How to install Mono-D

Install MonoDevelop(MD)/Xamarin Studio(XS)

Note: Xamarin Studio is basically a slightly different but still generally freely available version of MonoDevelop. In the following, MD can be seen equally to XS.
You'll need XS/MD >v5.6 to be installed for Mono-D.

On Windows/OSX

  1. Go to http://monodevelop.com/download, download & install the latest MonoDevelop setup. Note that there's a gtk# package required to be installed as well.
  2. Launch XS. Open the Help menu (Windows) or the Xamarin Studio menu (OSX) and select 'Check for updates'.
  3. Select the Alpha channel to be used for searching updates.
    Generally it's recommended to stick to the latest 'Alpha' version of XS because only then, you'll get the very latest & most recent changes & bug fixes. In my very long experience of using XS, it's usually not the case that an Alpha version behaves unstable.

On Linux

  1. Check your distro's software manager for any recent MonoDevelop version and try to install that one.
    MD >=5.6 is mandatory due to massive API changes etc.!
  2. If no proper build hasn't been uploaded, go to http://simendsjo.me/files/abothe and download the .xz matching your OS architecture.
  3. Follow the instructions given in the readme.txt in order to deploy everything properly.
    The archives are maintained by me, so please check the site regularly (like 1-2 times per month) for updates!
  4. Also it is possible to use build.opensuse.org. Instruction for Ubuntu 14.04:
    1. Add apt repository: sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/tpokorra:/mono/xUbuntu_14.04/ /' >> /etc/apt/sources.list.d/mono.list"
    2. Download key: wget http://download.opensuse.org/repositories/home:/tpokorra:/mono/xUbuntu_14.04/Release.key
    3. Add key: sudo apt-key add - < Release.key
    4. Update: sudo apt-get update
    5. Install: sudo apt-get install monodevelop-opt
    6. Run monodevelop-opt instead of monodevelop

Further requirements:

  • libgnomeui
  • xterm, gnome-terminal, mate-terminal OR konsole

Install Mono-D

  1. Make sure you've got dmd, optionally dub installed
    Either via downloading the zip distributables or via your linux distro's package manager. The packages are usually called dmd, druntime and dtools.
  2. Launch MD
  3. Click on the Tools (Windows)/Xamarin Studio (OSX) => Addin manager menu
  4. In the Gallery tab, hit the Refresh-button
  5. If there's an exception that some .mrep files could not be found,
    1. Open the repository drop-down menu
    2. click the Manage Repositories entry
    3. Add http://addins.monodevelop.com/Stable/Win32/5.0 (or, if it still fails: http://mono-d.alexanderbothe.com/repo)
  6. In the Language Bindings group, install the D Language Binding

Note: Before installing any new version of Mono-D on Windows, make sure you never opened any D project since the last start of XS or MD.
Otherwise, you'll get some installation errors etc which are caused by the fact that dlls cannot be overwritten once being loaded.

Setup Mono-D

There are further steps required to set up Mono-D properly:

  1. Open Edit => Preferences
    You'll find all D-related options in the Environment => D tree item.
  2. If the dmd executable cannot be found via $PATH or %PATH, adjust the compiler's bin path in the Compiler Toolchains settings to the absolute path.
    This also counts for OSX-Installations where XS is somehow not able to pass /usr/local/bin as default PATH entry..so just set the bin path over there as well!
  3. Do the same for dub or the Win32 ResourceCompiler.zip.
  4. In order to get the code completion running for phobos etc., activate the Includes tab in your compiler's settings and add the following lines (which you may fit to your machine's setup, of course)
    on Windows or the other respective paths for Linux:
    /usr/sha/include/dlang or
    or for OSX:
    You can of course add custom globally used libraries as well.
    Note that it's not sufficient to just reference the ...\dmd2\src\-path alone -- the \druntime\src\-folder will cause trouble otherwise because it then would parse runtime source codes twice and then will confuse equally named packages and modules!

Release Notes

See Mono-D Release Notes


Contribute & Support

If you like Mono-D, you may support Alex with a little tip for letting Mono-D become even better :-)

If you want to get your hands dirty and work on Mono-D on your own, follow these steps:

  • Uninstall Mono-D from MonoDevelop/XamarinStudio.
  • On Windows, restart XS.
  • git clone https://github.com/aBothe/Mono-D.git (or your own fork of the Mono-D repo)
  • cd Mono-D
  • git submodule init
  • git submodule update
  • Open up the MonoDevelop.DBinding.sln in MonoDevelop - or Visual Studio on Windows
  • Build Mono-D once (so the bin/Debug-Path becomes set up)
  • On Non-Windows, sudo ln -s -d "MonoDevelop.DBinding/bin/Debug" "/usr/lib/monodevelop/AddIns/mono-d" (adapt /usr/ to your own installation path where monodevelop has been installed to!)
  • On Windows, execute 'make symlink.bat' which is located in the repo's root.
  • Open MonoDevelop.D's Project settings
  • Head to the Custom Command-Tab
  • Adapt the given 'Run'-command path to MonoDevelop.exe to your system's setup. For Visual Studio, there should be a similar setting.
  • Now you can build & debug Mono-D directly from within MonoDevelop/Visual Studio.

Tutorials, Known Issues & Stuff

Build D Projects outside MonoDevelop

You still need a working MonoDevelop and Mono-D installation in order to proceed with the following step!

Just execute

mdtool build MyDSln.sln

to get e.g. a D project/solution built with Mono-D's facilities.

Note: You'll first off need to find mdtool in your XamarinStudio/MonoDevelop installation. On Linux, this command may look like

/opt/mono/bin/mdtool build MyDSln.sln

On Windows, this may looks like

"C:\Program Files (x86)\Xamarin Studio\bin\mdtool.exe" build MyDSln.sln

If you only have one .sln existing in a directory, just invoking mdtool inside that directory is also sufficient!

Dub Project fails to build under OSX

Generally it is to mention that XS does overwrite the system's $PATH environment variable when invoking dub or other native commands.

That overwritten $PATH does typically not contain /usr/local/bin - which is the reason why many dub setups will fail to work with Mono-D on OSX by default.
To fix this, just head to the 'D' -> 'Dub Settings' tab in the global options and enter e.g. /usr/local/bin/dub as 'dub executable'. Then, nearly everything should work fine.

Dub can't find dmd

If you're getting a build error message like

dub build "XYZ" "--build=plain"
Error executing command build:
Failed to invoke the compiler dmd to determine the build platform: /bin/bash: dmd: command not found

, you may set up your own dub executable 'proxy' so dub finds dmd again: For instance into /Users/<user>/monod_dub.sh:

export PATH="$PATH:/usr/local/bin"
dub $*

Now set /Users/<user>/monod_dub.sh to the 'D' -> 'Dub Settings' tab -> 'dub executable' option.

ld can't find custom D libs

It may also be the case that ld magically won't find your customly installed D libraries to link them in. In that case, see https://github.com/aBothe/Mono-D/issues/517

Additional Screenshots

Mono-D-on-Windows-Xamarin-5.2.png Mono-D-on-Fedora-KDE-Monodevelop-5.3.png