Sign in Join
Wiki copytemporary

Releasing units without source code: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Releasing units without source code

OldNewLine
1+It can be useful to release a FreePascal unit without publishing its source code:
2+
3+- The source code contains proprietary information.
4+- In teaching, because you want to force students to use a unit by its interface (contract) only, and not by looking at its implementation.
5+
6+FreePascal allows you to do so in the following way.
7+
8+The **provider** of the unit (and owner of its source code) should:
9+
10+- Compile the unit separately; it is recommended to use the compiler option **-Ur** (*Generate release unit files*; see *User's Manual* for details)
11+- Publish both the resulting ***.ppu** and ***.o** files. Also see Section 3.3 of the *User's Manual* (*Compiling a unit*).
12+
13+The **user** of the provided unit should:
14+
15+- Compile the using program (the *client*), such that the compiler can find both the ***.ppu** and ***.o** files of the unit (e.g. through the compiler option **-Fu**).
16+
17+Thus, there are two compiler contexts that matter:
18+
19+- The compiler installation of the provider
20+- The compiler installation of the user (client)
21+
22+## Notes
23+
24+- The provider and user should use the **same compiler version**. Although backwards compatibility between compiled units is never broken on purpose, this regularly happens in order to support new features or to fix bugs.
25+- The **Target OS** of the provided unit should match the target OS used for compiling the client program.
26+- If the provided unit depends on another unit *U*, then the unit *U* of the client context needs to be *compatible* with the unit *U* in the provider context. For that purpose, the providing compiler embeds a checksum of the **interface section** of unit *U* in the ***.ppu** file of the provided unit. The client compiler checks the embedded checksum against the checksum of unit *U* in the client context. If the checksums differ, then the client compiler will attempt to recompile the provided unit, and this will fail because the source is missing. With the compiler option **-vu** you get more information on the handling of unit files, and you can spot a line stating *Recompiling ..., checksum changed for ...*.
27+- In particular, the **System unit** of the provider context should be *compatible* with the System unit of the client context, because every unit implicitly depends on the System unit. Therefore, it is recommended to use a *stable release* of the compiler to compile the provided unit.
28+- There may be some other compiler options to consider (besides setting the Target OS):
29+ - **-M** (*Mode*)
30+ - **-C** (*Checking*), such as **-Cr** (*range checking*), **-Ci** (*i/o checking*), **-Co** (*overflow checking*), **-Ct** (*stack checking*)
31+ - **-Sa** (*Include assert statements in compiled code*)
32+ - **-O** (*Optimization*)
33+ - **-gl** (*Generating lineinfo code*)
34+- For older versions of the FreePascal compiler, the name of the provided unit's source file should be in all lower case letters. For recent versions of the compiler, this is no longer an issue. (The *User's Manual* is not up to date on this topic, I believe. **If you know more details, e.g. from which version on this changed, then please put it here.**)
35+
36+## See also
37+
38+- [[Lazarus Packages|Creating a closed source package]]
39+
40+---
41+*From the Free Pascal wiki, page "Releasing units without source code", as it stood on 2020-05-12 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
42+Category: FPC
43+Category: Packages

Back to history