IBM Support

Using Rhapsody with GNU/LLVM toolchains on Linux/Darwin targets

White Papers


Abstract

Author: Chris Sutton

This profile adds the following functionality to Rhapsody:

- Component support for Darwin operating systems.
- Component support for Static and Dynamic Shared libraries on UNIX-style operating systems.
- Build/execution of projects on remote targets using SSH
- Build/execution of projects using local (non-deployed) Docker containers

The profile uses stereotypes to set the target connection (Remote SSH or Local Container) and set the component type (Executable, Static Library, Dynamic Shared Library).

Build/execution functionality is integrated with the existing Rhapsody UI (Code menu and toolbar).

All scripting is provided and can be modified.

Content




Table of Contents
 

1. Supported Features
2. System Requirements
3. Setup
     3.1 Installation
     3.2 Profile structure
4. Getting Started
     4.1 Using the example projects
     4.2 Creating a New Project
     4.3 Adding a library component
     4.4 Adding an executable component
5. Modifying Settings
     5.1 Configuring SSH for a remote target
     5.2 Configuring a local docker container target
     5.3 Location for source code and binaries
     5.4 Choosing the static or dynamic shared object OXF libraries
     5.5 Modifying Static Library component Settings
     5.6 Modifying dynamic shared object (DSO) library component Settings
     5.7 Modifying executable binary component settings
     5.8 Modifying the OXF Framework
     5.9 Modifying the Build Framework, Invoke Make and Invoke Run toolbar operations
6. Getting the profile

 



1. Supported Features



This is a list of component types that can be created using the profile and the features that are supported.
 
Component Type OS Toolchain Language OXF DSO OXF Animation Docker
Unix Executable Linux/Darwin GNU/LLVM C and C++ Yes Yes Linux only***
Static Library Linux/Darwin GNU/LLVM C and C++ N/A* Yes Linux only***
Dynamic Shared Library Linux/Darwin GNU/LLVM C and C++ Yes No** Linux Only***


* Static libs can only be linked with executable binaries.
** OXF DSO makefile is currently not configured to build the animation libraries.
*** Docker containers can only run Linux guest environments. 

Tested versions in brackets.
 

2.1 Host Requirements
 
  • Windows 10 (Win10 Enterprise 1709 and Win10 Pro 1809)
  • Putty (0.71)
  • IBM Rhapsody (8.3.1)
     
2.2 Target Requirements
 
  • Ubuntu (16.x)
     
    • GNU Make (4.1)
    • GNU gcc (7.4.0)
    • GNU g++ (7.4.0)
  • Redhat (7.9)
     
    • GNU Make (3.82)
    • GNU gcc (4.8.5)
    • GNU g++ (4.8.5)
  • CentOS (7.9)
     
    • GNU Make (3.8.2)
    • GNU gcc (4.8.5)
    • GNU g++ (4.8.5)
  • macOS (High Sierra 10.13.6)
     
    • XCode 10.1 (Apple LLVM version 10.0.0, clang-1000.11.45.5, Target: x86_64-apple-darwin17.7.0)



3. Setup


3.1 Installation


i) Install IBM Rhapsody (C and C++) on the Windows 10 host machine
 
ii) unzip the NativeTarget profile zip into the Rhapsody/Share/profiles directory
For example, if Rhapsody was installed for "all users" in the ProgramData folder, the profile should be placed as follows:
 image 1168 (1)

iii) Add the following property to Rhapsody/Share/Properties/siteC++.prp
 
Subject CPP_CG
    Metaclass Configuration 
        Property Environment Enum "NativeTarget,MSVC,MSVCDLL,MSVCStandardLibrary,VxWorks,VxWorks6diab,VxWorks6gnu,VxWorks6diab_RTP,VxWorks6gnu_RTP,Solaris2,Cygwin,MicrosoftWinCE600,OseSfk,Linux,Solaris2GNU,QNXNeutrinoGCC, QNXNeutrinoMomentics,NucleusPLUS-PPC,WorkbenchManaged,WorkbenchManaged653,WorkbenchManaged_RTP" "NativeTarget"
    end
end

For example:
 Screen Shot 2019-06-04 at 17.39.24 0

iv) Open powershell console as administrator and run command:
set-executionpolicy -scope currentuser unrestricted
v) Install Putty on the Win10 host machine
vi) Install make, binutils, gcc and g++ tools on Linux target OR install xcode on macOS target. 


3.2 Profile structure
 
Folder Description
dockerfile location for docker files used to create custom docker images/containers
env location for modified OXF source files
examples location for example C and C++ projects
profile The NativeTargetProfile model file
properties The default set of properties used by the profile. These are mostly overridden in the profile stereotypes.
scripts Location of Code menu/toolbar functionality scripts and other utility scripts.
 

4. Getting Started
 

4.1 Using the example projects

Here is a quick overview of the example projects. Two example projects are provided with the profile, one for C and one for C++.  Both examples contain six components.

Screen Shot 2019-06-06 at 15.07.08 0


The components are defined as follows:
 
Component Description
CLANGSTATICLIB Static library for Darwin/LLVM target
CLANGSHAREDLIB Shared library for Darwin/LLVM target
CLANGEXE Executable binary for Darwin/LLVM target
GCCSTATICLIB Static library for Linux/GNU target
GCCSHAREDLIB Shared library for Linux/GNU target
GCCEXE Executable binary for Linxu/GNU target    


The scope for each contains a class with statechart. Each statechart prints a simple message to standard output. 
 

Screen Shot 2019-06-04 at 16.33.36 2

Now lets build and run the projects:
 
i) Configure your target connection. See section 5.1 Configuring SSH for a remote target
and 5.2 Configuring a local docker container target for configuring targets. 

ii) Open the features window for the project and set the stereotype for your target connection. Select only one stereotype from TestPkg.

Screen Shot 2019-06-06 at 10.54.18 1

iii) Set the active component to either GCCSTATICLIB or CLANGSTATICLIB (depends on the target selected in previous step)

Screen Shot 2019-06-05 at 14.38.39 0

iv) Use Build Framework from the Code menu to compile the OXF on the target.

Screen Shot 2019-06-05 at 14.40.51 3

The OXF build process will proceed at the output window. This can take a few minutes, depending on network speeds.

v) Using the "Generate/Make/Run" toolbar button, build the three components for your target in turn.

Screen Shot 2019-06-05 at 15.29.28 0

For example, GCCSTATICLIB, GCCSHAREDLIB and GCCEXE.  Or CLANGSTATICLIB, CLANGSHAREDLIB and CLANGEXE.

In addition to the normal model checker and code generation messages, the output window now also shows additional messages:

  • User Authentication based on the credentials added to the logins.txt file
  • Connection status to the remote target
  • Transfer of project source files to the remote target (including source/target filesystem locations)
  • Build of project source files
  • Transfer of binary files. DSO libraries are copied to /usr/local/lib automatically so they can be found during runtime. Executable binaries are copied back to the local host to enable the "Run" button in the Rhapsody code toolbar.
  • Build summary. Runs "file" command on the finished binary file.
     

Screen Shot 2019-06-06 at 11.12.24

Since we have used the GMR button the executable component will automatically run after the build completes. It will open a terminal window, connect to the target and execute.


4.2 Creating a new project


Create a new C or C++ project as usual.
Use Add profile to model in the File menu to add the NativeTargetProfile to the project.


Screen Shot 2019-06-04 at 16.38.04 0


4.3 Adding a Library component 

  • Add a component
  • Set the Type to Library in the general tab
  • Set the corresponding stereotype for the OS/toolchain/language
     
    Stereotype Name Description
    DSHARED_CPP Darwin/LLVM DSO lib for C++
    DSHARED_C Darwin/LLVM DSO for C
    LSHARED_CPP Linux/GNU DSO for C++
    LSHARED_C Linux/GNU DSO for C
    DSTATIC_CPP Darwin/LLVM static lib for C++
    DSTATIC_C Darwin/LLVM static lib for C
    LSTATIC_CPP Linux/GNU static lib for C++
    LSTATIC_C Linux/GNU static lib for C

    For example:

    Screen Shot 2019-06-04 at 16.42.27
     
  • Add your model elements to the project as normal. 
  • Select these model elements under the new component's Scope tab.
  • Use the toolbar GMR button or the individual code > generate/make/run commands


    
4.4 Adding an executable component
 

  • Add a component
  • Set the Type to Executable in the general tab
  • Set the corresponding stereotype for the OS/toolchain/language
     
    Stereotype Name Description
    DEXE_CPP Darwin/LLVM executable binary for C++
    DEXE_C Darwin/LLVM executable binary for C
    LEXE_CPP Linux/GNU executable binary for C++
    LEXE_C Linux/GNU executable binary for C
  •  Add your model elements to the project as normal. 
  • Select these model elements under the new component's Scope tab.
  • Use the toolbar GMR button or the indiviudal code > generate/make/run commands



5. Modifying Settings 


5.1 Configuring SSH for a remote target


i) Configure the target and host to send/receive connections:
a) You must enable the File and Printer Sharing (Echo Request - ICMPv4-In) rules on the Windows 10 host.
b) You must configure the firewall on your macOS target to allow ICMP traffic.
c) You must enable SSH on the macOS target. Preferences > Sharing > Remote Sharing. Don't forget to setup access for a specific user.

ii) Connect to the remote target using the Putty client at least once before using the connection in Rhapsody.
You will receive this message:
 
Screen Shot 2019-06-04 at 17.17.19

You must select YES or Rhapsody will be unable to connect.

iii) For security reasons your passwords will not be stored in the Rhapsody model. Instead login credentials are stored in the scripts\logins.txt file.

Screen Shot 2019-06-04 at 17.04.25 0

Note this format is compatible with Powershell hashtables. This code for this mechanism can be found in scripts\misc\common.ps1. 

iv) Select the remote target in Rhapsody:
 
  • Add a new stereotype with a name describing your target. e.g. MacbookRemote or UbuntuDesktop
  • Set the stereotype applicable to Component and Project.
  • Add a generalization from the your stereotype to the NativeTargetProfile::remote stereotype.
     

    If you're using the example projects you can skip the above steps and use one of the stereotypes provided.
     
  • Set the following properties:
     
    Property Name Description
    NativeTarget::Configuration::RemoteTarget    This should be the IP address or FQDN of the remote target
    NativeTarget::Configuration::RemoteTargetUsername This is the user name for the remote target account
    NativeTarget::Configuration::RemotePwdFile This is the username/password file. It is located in the profile/scripts folder.

    For example:

     Screen Shot 2019-06-04 at 16.48.20 0
     
  • Apply your stereotype to the component.
     
This document will not cover the basics of using Docker. You are expected to have some experience using Docker before continuing.
 
Note you must have Docker or Docker Toolbox installed locally and running. Since Docker uses Hypervisers this setting can only be used on a physical machine.  Other virtualization software such as VirtualBox or VMWare must be exited.
    
The docker image must be setup before using. Please see the Docker Reference for a list of commands.

See Docker Hub for list of existing images.  Images created from custom docker files can also be used.
    
To use your docker image in Rhapsody:
    
  • Add a new stereotype with a name describing your docker target. e.g. DockerUbuntu 
  • Set the stereotype applicable to Component and Project.
  • Add a generalization from the your stereotype to the NativeTargetProfile::virtual stereotype.
  • Set the properties:
 
Property Name Description
NativeTarget::Configuration::VirtualImageName The name of the image.
NativeTarget::Configuration::VirtualContainerName This is an arbitrary value for the new container instance.
NativeTarget::Configuration::VirtualContainerTag If left blank, "latest" tag will be used. 
     
  • Apply your stereotype to the component.

Note that the specified docker container will be destroyed/created when Build Framework is run from the Code menu.
 

5.3 Location for source code and binaries.
 

  • Project code is copied to the following locations on the target

    • For Darwin: /Users/<Username>/rhp_workspace

    • For Linux: /root/rhp_workspace or /home/<Username>/rhp_workspace

    • <Username> is set by the NativeTarget::Configuration::RemoteTargetUsername property. If you set "root" as the username for Linux targets the alternative path will be used. See "Setting the login credentials for your target" section.

  • Project binaries are built in the component/configuration path as per usual Rhapsody behavior.

    • OXF code is copied and built at the rhp_workspace/Share location for both Darwin and Linux.

    • DSO libraries are copied to /usr/local/lib to allow easy access during runtime. Note that the C and C++ OXF DSO libraries have the same name so  will overwrite each other. Therefore, you must rebuild the OXF when switching between C and C++ projects.

    • The "rhp_workspace" default can be changed by modifying the $rhpWorkspace variable in all three powershel scripts located in the \scripts\ssh\ folder of the profile.


5.4 Choosing the static or dynamic shared object OXF libraries

     
When the OXF framework is rebuilt, a static version of the OXF and a dynamically shared object version of OXF are automatically created on the target OS. You can select which library type is selected for your project with the property:
  • CPP_CG::NativeTarget::UseOXFDSO

Since all components will need to use the same library type it is recommend that this property is set at the project level.

Note that reactive objects in a DSO component will not run when UseOXFDSO = False. For example, a global function or class member operation will be called but a state-chart will not execute.
The static library build settings use the GNU archiver utility (ar) to package together object files for both Darwin and Linux targets.
 
Property Name Description
<Lang>_CG::NativeTarget::CC The compiler command used to create the objects files
<Lang>_CG::NativeTarget::CPPCompileDebug The compile flags used when the project configuration is set to "debug"
<Lang>_CG::NativeTarget::CPPCompileRelease The compile flags used when the project configuration is set to "release"
<Lang>_CG::NativeTarget::LIB_CMD The ar command. This will not need to be changed in most situations
<Lang>_CG::NativeTarget::LibExtension the extension of the static library. The extension will be ".a" for most situations
<lang>_CG::NativeTarget::LIB_FLAGS the switches to be used with the linker command.  This may change depending on the target operating system version. Check your OS "ar" man pages for details on supported switches/flags.
<Lang>_CG::NativeTarget::MakeFileContent This contains the makefile itself (and references the above properties). Advanced use only
The dynamically shared object (DSO) library build settings use the GNU (g++) or LLVM (clang++) linker to build a binary library from the compiled object files.
 
Property Name Description
<Lang>_CG::NativeTarget::CC The compiler command used to create the objects files. This will depend on the language and toolchain (GNU/LLVM) selected
<Lang>_CG::NativeTarget::CPPCompileDebug The compile flags used when the project configuration is set to "debug". Darwin requires shared library objects to be compiled with "-dynamiclib" option. Linux requires shared library objects to be compiled with "-shared -fPIC" options. 
<Lang>_CG::NativeTarget::CPPCompileRelease The compile flags used when the project configuration is set to "release".
<Lang>_CG::NativeTarget::LIB_CMD The linker command. e.g. g++ or clang++
<Lang>_CG::NativeTarget::LibExtension the extension of the static library file to be built. The extension will be ".so" for Linux, ".dylib" for Darwin.
<lang>_CG::NativeTarget::LIB_FLAGS the switches to be used with the linker command.  Darwin requires shared libraries to be linked with "-dynamiclib" option. Linux requires shared libraries to be linked with "-shared -fPIC" options. Additionally, Linux requires you to link Rhapsody OXF and your project with the POSIX Realtime Extensions library ("-lrt" option).


    
5.7. Modifying executable binary component settings
 

Executable binary build settings use the GNU (g++) or LLVM (clang++) linker to build a binary executable from the compiled object files.
 
Property Name Description
<Lang>_CG::NativeTarget::CC The compiler command used to create the objects files. This will depend on the language and toolchain (GNU/LLVM) selected.
<Lang>_CG::NativeTarget::CPPCompileDebug The compile flags used when the project configuration is set to "debug".
<Lang>_CG::NativeTarget::CPPCompileRelease The compile flags used when the project configuration is set to "release".
<Lang>_CG::NativeTarget::LinkCommand The linker command. e.g. g++ or clang++
<Lang>_CG::NativeTarget::ExeExtension the extension of the executable binary file to be built. This is set to empty string (no extension)

    

5.8. Modifying the OXF Framework


The OXF source files for Linux and Darwin can be found in the env\Linux and env\Darwin folders of the profile. The files are archived as Share.tar files. These archive files are copied over to the remote target, before being unpacked and rebuilt. Therefore, to make changes to these source files you must first unpack them locally to make changes, then re-pack them before using Build Framework from the Code menu. Please ensure that you save source files with Unix-like EOL conversions. It is recommended to use 7zip to create the tar file and that the PathMode option is set to "Full Pathnames".

    
5.9. Modifying the Build Framework, Invoke Make and Invoke Run toolbar operations


The toolbar button functionality is defined by the following properties defined in properties\NativeTargetProfile.prp:
 

Property Name Description
<Lang>_CG::NativeTarget::buildFrameworkCommand Calls the buildFramework.ps1 script
<Lang>_CG::NativeTarget::InvokeMake Calls the buildProject.ps1 script
Calls the buildProject.ps1 script Calls the runProject.ps1 script



Powershell scripts are located in the scripts folder of the profile directory. Rhapsody properties are sent to the scripts as parameters.



6. Getting the profile
 

This profile is available by request only. Please visit IBM Rhapsody Support and open a support ticket:

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Component":"","Platform":[{"code":"PF033","label":"Windows"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

ibm10886027